home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 1997 / CT_SW_97.ISO / pc / software / betriebs / macos / frodo404.hqx / Frodo v4.0.4 / 1541 Disk Drive Guide.TXT next >
Text File  |  1996-01-15  |  152KB  |  3,909 lines

  1. *********
  2.  
  3. Welcome to Project 64!
  4.  
  5. The goal of Project 64 is to preserve Commodore 64 related documents
  6. in electronic text format that might otherwise cease to exist with the
  7. rapid advancement of computer technology and declining interest in 8-
  8. bit computers on the part of the general population.
  9.  
  10. Extensive efforts were made to preserve the contents of the original
  11. document.  However, certain portions, such as diagrams, program
  12. listings, and indexes may have been either altered or sacrificed due
  13. to the limitations of plain vanilla text.  Diagrams may have been
  14. eliminated where ASCII-art was not feasible.  Program listings may be
  15. missing display codes where substitutions were not possible.  Tables
  16. of contents and indexes may have been changed from page number
  17. references to section number references. Please accept our apologies
  18. for these limitations, alterations, and possible omissions.
  19.  
  20. The author(s) of the original document and members of Project 64 make
  21. no representations about the accuracy or suitability of this material
  22. for any purpose.  This etext is provided "as-is".  Please refer to the
  23. warantee of the original document, if any, that may included in this
  24. etext.  No other warantees, express or implied, are made to you as to
  25. the etext or any medium it may be on.  Neither the author(s) nor the
  26. members of Project 64 will assume liability for damages either from
  27. the direct or indirect use of this etext or from the distribution of
  28. or modification to this etext.
  29.  
  30. *********
  31.  
  32. The Project 64 etext of the Commodore 1541 Disk Drive User's Guide,
  33. first edition.  Converted to etext by the Basic Bombardier.  Some
  34. errors in the original document were corrected in this etext.
  35.  
  36. 1541D10A.TXT, January 1996, etext #7
  37.  
  38. *********
  39.  
  40. Note: To extract the ascii text basic programs all at once from this
  41. etext use "tok64" by Cris Berneburg <74171.2136@compuserve.com>. Or to
  42. extract the uuencoded basic programs all at once use "uud" by Edwin
  43. Kremer <edwin@zlotty>.
  44.  
  45. *********
  46.  
  47. COMMODORE 1541 DISK DRIVE USER'S GUIDE
  48.  
  49. A Friendly Introduction to Your 1541 Disk Drive
  50.    _____
  51.   /  ___|___
  52.  |  /   |__/  c o m m o d o r e
  53.  |  \___|__\  C O M P U T E R
  54.   \_____|
  55.  
  56. INFORMATION TO USER
  57.  
  58. "WARNING: THIS EQUIPMENT HAS BEEN CERTIFIED TO COMPLY WITH THE LIMITS
  59. FOR A CLASS B COMPUTING DEVICE, PURSUANT TO SUBPART J OF PART 15 OF
  60. FCC RULES.  ONLY PERIPHERALS (COMPUTER INPUT/OUTPUT DEVICES, TERMINALS,
  61. PRINTERS, ETC.) CERTIFIED TO COMPLY WITH THE CLASS B LIMITS MAY BE
  62. ATTACHED TO THIS COMPUTER.  OPERATION WITH NON-CERTIFIED PERIPHERALS
  63. IS LIKELY TO RESULT IN INTERFERENCE TO RADIO AND TV RECEPTION."
  64.  
  65. "THIS EQUIPMENT GENERATES AND USES RADIO FREQUENCY ENERGY AND IF NOT
  66. INSTALLED PROPERLY, THAT IS, IN STRICT ACCORDANCE WITH THE
  67. MANUFACTURER'S INSTRUCTIONS, MAY CAUSE INTERFERENCE TO RADIO AND
  68. TELEVISION RECEPTION.  IT HAS BEEN TYPE TESTED AND FOUND TO COMPLY
  69. WITH THE LIMITS FOR A CLASS B COMPUTING DEVICE IN ACCORDANCE WITH THE
  70. SPECIFICATIONS IN SUBPART J OF PART 15 OF FCC RULES, WHICH ARE
  71. DESIGNED TO PROVIDE REASONABLE PROTECTION AGAINST SUCH INTERFERENCE IN
  72. A RESIDENTIAL INSTALLATION.  HOWEVER, THERE IS NO GUARANTEE THAT
  73. INTERFERENCE WILL NOT OCCUR IN A PARTICULAR INSTALLATION.  IF THIS
  74. EQUIPMENT DOES CAUSE INTERFERENCE TO RADIO OR TELEVISION RECEPTION,
  75. WHICH CAN BE DETERMINED BY TURNING THE EQUIPMENT OFF AND ON, THE USER
  76. IS ENCOURAGED TO TRY TO CORRECT THE INTERFERENCE BY ONE OR MORE OF THE
  77. FOLLOWING MEASURES:
  78.  
  79. * REORIENT THE RECEIVING ANTENNA
  80.  
  81. * RELOCATE THE COMPUTER WITH RESPECT TO THE RECEIVER
  82.  
  83. * MOVE THE COMPUTER AWAY FROM THE RECEIVER
  84.  
  85. * PLUG THE COMPUTER INTO A DIFFERENT OUTLET SO THAT COMPUTER AND
  86. RECEIVER ARE ON DIFFERENT BRANCH CIRCUITS
  87.  
  88. "IF NECESSARY, THE USER SHOULD CONSULT THE DEALER OR AN EXPERIENCED
  89. RADIO/TELEVISION TECHNICIAN FOR ADDITIONAL SUGGESTIONS.  THE USER MAY
  90. FIND THE FOLLOWING BOOKLET PREPARED BY THE FEDERAL COMMUNICATIONS
  91. COMMISSION HELPFUL: 'HOW TO IDENTIFY AND RESOLVE RADIO-TV INTERFERENCE
  92. PROBLEMS.' THIS BOOKLET IS AVAILABLE FROM THE U.S. GVERNMENT PRINTING
  93. OFFIC, WASHINGTON, D.C. 2402, STOCK NO. 004-000-00345-4."
  94.  
  95. PART NO: 320970
  96.  
  97. The information in this manual has been reviewed and is believed to be
  98. entirely reliable.  No responsibility, however, is assumed for
  99. inaccuracies.  The material in this manual is for information purposes
  100. only, and is subject to change without notice.
  101.  
  102. (C) Commodore Business Machines Electronics Ltd., September 1982
  103.  
  104. "All rights reserved."
  105.  
  106.  
  107.  
  108. Table of Contents                                  [ Section ]
  109.  
  110. 1. GENERAL DESCRIPTION
  111.     [ Introduction........................................ 1 ]
  112.     [ Specifications...................................... 2 ]
  113.  
  114. 2. UNPACKING AND CONNECTING
  115.       Contents of Box..................................... 1
  116.       Connection of Cables................................ 2
  117.       Powering On......................................... 3
  118.       Insertion of Diskette............................... 4
  119.       Using with VIC 20 or Commodore 64................... 5
  120.  
  121. 3. USING PROGRAMS
  122.       Loading Pre-packaged Software....................... 1
  123.       LOAD................................................ 2
  124.       Directory of Disk................................... 3
  125.       Pattern Matching & Wild Cards....................... 4
  126.       SAVE................................................ 5
  127.       SAVE and replace.................................... 6
  128.       VERIFY.............................................. 7
  129.       DOS Support Program................................. 8
  130.  
  131. 4. DISK COMMANDS
  132.       OPEN AND PRINT #.................................... 1
  133.       NEW................................................. 2
  134.       COPY................................................ 3
  135.       RENAME.............................................. 4
  136.       SCRATCH............................................. 5
  137.       INITIALIZE.......................................... 6
  138.       VALIDATE............................................ 7
  139.       DUPLICATE........................................... 8
  140.       Reading the Error Channel........................... 9
  141.       CLOSE...............................................10
  142.  
  143. 5. SEQUENTIAL FILES
  144.       OPEN................................................ 1
  145.       PRINT# and INPUT#................................... 2
  146.       GET#................................................ 3
  147.       Reading the Directory............................... 4
  148.  
  149. 6. RANDOM FILES
  150.     [ Explanation......................................... 1 ]
  151.       Opening a channel for random access data............ 2
  152.       BLOCK-READ.......................................... 3
  153.       BLOCK-WRITE......................................... 4
  154.       BLOCK-ALLOCATE...................................... 5
  155.       BLOCK-FREE.......................................... 6
  156.     [ Using Random Files.................................. 7 ]
  157.       BUFFER-POINTER...................................... 8
  158.       USER1 and USER2..................................... 9
  159.  
  160. 7. RELATIVE FILES
  161.     [ Introduction........................................ 1 ]
  162.       Creating a relative file............................ 2
  163.       Using relative files................................ 3
  164.       Create a relative file.............................. 4
  165.       Summary............................................. 5
  166.       Modifying the program............................... 6
  167.  
  168. 8. PROGRAMNUNG THE DISK CONTROLLER
  169.       BLOCK-EXECUTE....................................... 1
  170.       MEMORY-READ......................................... 2
  171.       MEMORY-WRITE........................................ 3
  172.       MEMORY-EXECUTE...................................... 4
  173.       USER Commands....................................... 5
  174.  
  175. 9. CHANGING THE DISK DEVICE NUMEBER
  176.       Software Method..................................... 1
  177.       Hardware Method..................................... 2
  178.  
  179. 10. ASSEMBLY LANGUAGE AND THE 1541
  180.  
  181. Appendices
  182.       A. Disk Command Summary
  183.       B. Error Messages
  184.       C. Demonstration Disk Programs
  185.       D. Disk Formats Tables
  186.  
  187. [ Index ]
  188.  
  189. [ Commodore Sales Centers ]
  190.  
  191. [ Back Page ]
  192.  
  193.  
  194.  
  195. 1. GENERAL DESCRIPTION
  196.  
  197. 1.1 INTRODUCTION
  198.  
  199. Welcome to the fastest, easiest, and most efficient filing system
  200. available for your Commodore 64 or VIC 20 computer, your 1541 DISK
  201. DRIVE.  This manual has been designed to show you how to get the most
  202. from your drive, whether you're a beginner or an advanced professional.
  203.  
  204.  
  205. If you are a beginner, the first few chapters will help you through
  206. the basics of disk drive installation and operation.  As your skill
  207. and programming knowledge improves, you will find more uses for your
  208. disk drive and the more advanced chapters of this manual will become
  209. much more valuable.
  210.  
  211. If you're a professional, this reference guide will show you how to
  212. put the 1541 through its paces to perform just about all the disk
  213. drive jobs you can think of.
  214.  
  215. No matter what level of expertise you have, your 1541 disk drive will
  216. dramatically improve the overall capabilities of your computer system.
  217.  
  218. Before you get to the details of 1541 operation, you should be aware
  219. of a few important points.  This manual is a REFERENCE GUIDE, which
  220. means that unless the information you seek directly pertains to the
  221. disk or disk drive you will have to use your Commodore 64 or VIC 20
  222. User's Guides and Programmer's Reference Guides to find programming
  223. information.  In addition, even though we give you step-by-step
  224. instructions for each operation, you should become familiar with BASIC
  225. and the instructions (called commands) that help you operate your
  226. disks and drives.  However, if you just want to use your disk drive
  227. unit to load and save prepackaged software, we've included an easy and
  228. brief section on doing just that.
  229.  
  230. Now ... let's get on with the general information.
  231.  
  232. The commands for the disk drive come in several levels of
  233. sophistication.  Starting in chapter three, you can learn how the
  234. command that allow you to SAVE and LOAD programs with the disk work.
  235. Chapter four teaches you how commands are sent to the disk, and
  236. introduces the disk maintenance commands.
  237.  
  238. Chapter five tells you how to work with SEQuential data files.  These
  239. are very similar to their counterparts on tape (but much faster).
  240. Chapter six introduces the commands that allow you to work with random
  241. files, to access any piece of data on the disk, and how you organize
  242. the diskette into tracks and blocks.  Chapter seven describes the
  243. special relative files.  RELative files are the best method of storing
  244. data bases, especially when they are used along with sequential files.
  245.  
  246. Chapter eight describes methods for programming the disk controller
  247. circuits at the machine language level.  And the final chapter shows
  248. you how to change the disk device number, by cutting a line inside the
  249. drive unit or through software.
  250.  
  251. Remember, you don't really need to learn everything in this book all
  252. at once.  The first four chapters are enough to get you going, and the
  253. next couple are enough for most operations.  Getting to know your disk
  254. drive will reward you in many ways -- speed of operation, reliability,
  255. and much more flexibility in your data processing capabilities.
  256.  
  257.  
  258.  
  259. 1.2 SPECIFICATIONS
  260.  
  261. This disk drive allows you to store up to 144 different programs
  262. and/or data files on a single mini-floppy diskette, for a maximum of
  263. over 174,000 bytes worth of information storage.
  264.  
  265. Included in the drive is circuitry for both the disk controller and a
  266. complete disk operating system, a total of 16K of ROM and 2K of RAM
  267. memory.  This circuitry makes your Commodore 1541 disk drive an
  268. "intelligent" device.  This means it does its own processing without
  269. taking any memory away from your Commodore 64 or VIC 20 computer.  The
  270. disk uses a "pipeline" software system.  The "pipeline" makes the disk
  271. able to process commands while the computer is performing other jobs.
  272. This dramatically improves the overall throughput (input and output)
  273. of the system.
  274.  
  275. Diskettes that you create in this disk drive are read and write
  276. compatible with Commodore 4040 and 2031 disk drives.  Therefore,
  277. diskettes can be used interchangeably on any of these systems.  In
  278. addition, this drive can read programs created on the older Commodore
  279. 2040 drives.
  280.  
  281. The 1541 disk drive contains a dual "serial bus" interface.  This bus
  282. was specially created by Commodore.  The signals of this bus resemble
  283. the parallel IEEE-488 interface used on Commodore PET computers,
  284. except that only one wire is used to communicate data instead of eight.
  285.  The two ports at the rear of the drive allows more than one device to
  286. share the serial bus at the same time.  This is accomplished by
  287. "daisy-chaining" the devices together, each plugged into the next. Up
  288. to five disk drives and one printer can share the bus simultaneously.
  289.  
  290. Figure 1.1 Specifications VIC 1540/1541 Single Drive Floppy Disk
  291.  
  292. STORAGE
  293.  
  294.     Total capacity       174848 bytes per diskette
  295.     Sequential           168656 bytes per diskette
  296.     Relative             167132 bytes per diskette
  297.                          65535 records per file
  298.     Directory entries    144 per diskette
  299.     Sectors per track    17 to 21
  300.     Bytes per sector     256
  301.     Tracks               35
  302.     Blocks               683 (664 blocks free)
  303.  
  304. IC's:
  305.  
  306.     6502                 microprocessor
  307.     6522 (2)             I/O, internal timers
  308.  
  309.     Buffer
  310.       2114 (4)           2K RAM
  311.  
  312. PHYSICAL:
  313.  
  314.     Dimensions
  315.       Height              97 mm
  316.       Width              200 mm
  317.       Depth              374 mm
  318.  
  319. Electrical:
  320.  
  321. Power Requirements
  322.       Voltage            100, 120, 220, or 240 VAC
  323.       Frequency          50 or 60 Hertz
  324.       Power              25 Watts
  325.  
  326. MEDIA:
  327.  
  328. Diskettes                Standard mini 5 1/4", single sided,
  329.                          single density
  330.  
  331.  
  332.  
  333. 2. UNPACKING AND CONNECTING
  334.  
  335. 2.1 CONTENTS OF BOX
  336.  
  337. Included with the 1541 disk drive unit, you should find a gray power
  338. cable, black serial bus cable, this manual, and a demonstration
  339. diskette.  The power cable has a connection for the back of the disk
  340. drive on one end, and for a grounded (three-prong) electrical outlet
  341. on the other.  The serial bus cable is exactly the same on both ends.
  342. It has a 6-pin DIN plug which attaches to the VIC 20, Commodore 64 or
  343. another disk drive.
  344.  
  345. Please, don't hook up anything until you've completed the following
  346. section!
  347.  
  348.                                       Fig 1.A
  349.  +------------------------------------------+
  350.  |                                          |
  351.  |  +------------------------------------+  |
  352.  |  | C= commodore ========       1541   |  |
  353.  |  +------------------------------------+  |
  354.  |      +----------------------------+      |
  355.  |      |                            |      |
  356.  +------| ========================== |------+
  357.  |      |          |      |          |      |
  358.  |  O   |     O    +------+          |      |
  359.  |  |   +-----|----------------------+      |
  360.  +--|---------|-----------------------------+
  361.     |         |
  362.     |         +-- DRIVE INDICATOR (RED LED)
  363.     |                             LIGHT: ACTIVE
  364.     |                             FLASH: ERROR
  365.     +-- POWER INDICATOR
  366.         (GREEN LED) LIGHT: POWER ON
  367.  
  368.  Fig 1. Front Panel
  369.  
  370.                                       Fig 1.B
  371.  +------------------------------------------+
  372.  |                                          |
  373.  |  +------------------------------------+  |
  374.  |  | C= commodore ========       1541   |  |
  375.  |  +------------------------------------+  |
  376.  |      +----------------------------+      |
  377.  |      |     O----+------+          |      |
  378.  +------| ====|===================== |------+
  379.  |      |     |    |      |          |      |
  380.  |  O   |   ==|    |      |          |      |
  381.  |  |   +---|--\---+------+----------+      |
  382.  +--|-------|---|---------------------------+
  383.     |       |   |
  384.     |       |   +-- DOOR LEVER
  385.     |       |
  386.     |       +---- DRIVE INDICATOR (RED LED)
  387.     |                             LIGHT: ACTIVE
  388.     |                             FLASH: ERROR
  389.     +-- POWER INDICATOR
  390.         (GREEN LED) LIGHT: POWER ON
  391.  
  392.  
  393.  
  394.                     +-- POWER SWITCH
  395.  Fig 2. Back Panel  |
  396.                     |       +------+-- SERIAL BUS
  397.  +------------------|-------|------|--------+
  398.  |                  |      _|_    _|_       |
  399.  |                  |     / _ \  / _ \      |
  400.  |      +-----------+    | |_| || |_| |     |
  401.  |      |                 \___/  \___/      |
  402.  |    __|__   ________     ___              |
  403.  |    |+-+|  / ______ \   / _ \             |
  404.  +----|| ||-|--|    |--|-|-|_|-|------------+
  405.  |    |+-+| |  |____|  |  \___/             |
  406.  |    +---+ +----|-----+    |               |
  407.  |               |          |               |
  408.  +---------------|----------|---------------+
  409.                  |          |
  410.       AC INPUT --+          +-- FUSE/HOLDER
  411.  
  412.  
  413.  
  414. 2.2 CONNECTION OF CABLES
  415.  
  416. Your first step is to take the power cable and insert it into the back
  417. of the disk drive (see figure 2).  It won't go in if you try to put it
  418. in upside down.  Once it's in the drive, plug the other end into the
  419. electrical outlet.  If the disk drive makes any sound at this time,
  420. please turn it off using the switch on the back!  Don't plug any other
  421. cables into the disk drive if the power is on.
  422.  
  423. Next, take the serial bus cable and attach it to either one of the
  424. serial bus sockets in the rear of the drive.  Turn off the computer,
  425. and plug the other end of the cable into the back of the computer.
  426. That's all there is to it!
  427.  
  428. If you have a printer, or any additional disk drives, attach the
  429. cables into the second serial bus port (see figure 3).  For directions
  430. on using multiple drives at one time, read chapter 9. If you are a
  431. first-time user with more than one drive, start working with only one
  432. drive until you're comfortable with the unit.
  433.  
  434.                                    +--------+
  435.  +---------------------------+     |  +-----|---+
  436.  |  ============= O O        |     |  |     O O----+
  437.  |                  | == === |     |  | #[]o    |  |
  438.  +------------------|--------+     |  +---------+  |
  439.   Commodore 64 or   |              |  VIC 1541     |
  440.   VIC20 Personal    | Serial cable |  Single Drive |
  441.      Computer       +--------------+  Floppy Disk  |
  442.                                                    |
  443.                                                    |
  444.                                    Serial cable    |
  445.                            +-----------------------+
  446.                            |
  447.                            |       +---------------+
  448.  Fig 3. Floppy Disk        |       |               |
  449.         Hookup             |       +-+-------------+
  450.                            |         |  Printer
  451.                            +---------+
  452.  
  453. 2.3 POWERING ON
  454.  
  455. When you have all the devices hooked together, it's time to start
  456. turning on the power.  It is important that you turn on the devices in
  457. the correct order.  The computer should always be turned on last.  As
  458. long as the computer is the last one to be turned on, everything will
  459. be OK.
  460.  
  461. First, make sure that you've removed all diskettes from the disk
  462. drives before powering on.
  463.  
  464. After all the other devices have been turned on, only then is it safe
  465. to turn on the computer.  All the other devices will go through their
  466. starting sequences.  The printer's motor goes on, with the print head
  467. moving halfway across the line and back again.  The 1541 disk drive
  468. will have its green light on, and then the red drive/error light will
  469. blink, while your TV screen forms the starting picture.
  470.  
  471. Once the red drive/error light has stopped flashing on the drive, it
  472. is safe to begin working with it.
  473.  
  474.  
  475.  
  476.                     +-------U-===-U-------+       /\
  477.                     |         | |         |     /    \
  478.                     |         |_|         |   /_      _\ INSERT
  479.                     |         ___         |     |    |    INTO
  480.                     |     O  /   \        |     |    |    DRIVE
  481.         WRITE       |       |     |       |     |    |
  482.         PROTECT     |        \___/        |     |    |
  483.         NOTCH ------]                     |     |____|
  484.                     |                     |
  485.                     +---------------------+
  486.  WHEN COVERED, DISKETTE
  487.  CONTENTS CANNOT BE ALTERED
  488.  
  489.  Fig.4. Postition for Diskette Insertion
  490.  
  491.  
  492.  
  493. 2.4 INSERTION OF DISKETTE
  494.  
  495. There is different way to open and close the drive door, and
  496. insertion/removal the diskette.
  497.  
  498. TYPE 1: figure 1.A -- To open the door on the drive, simply press the
  499. door catch lightly, and the door will pop open. If there is a diskette
  500. in the drive, it is ejected by a small spring.  Take the diskette to
  501. be inserted, and place it in the drive face-up with the large opening
  502. going in first and write-protect notch to the left (covered with tape
  503. in the demonstration disk) (see figure 4).
  504.  
  505. Press it in gently, and when the diskette is in all the way, you will
  506. feel a click and the diskette will not spring out.  Close the drive
  507. door by pulling downward until the latch clicks into place.  Now you
  508. are ready to begin working with the diskette.
  509.  
  510. TYPE 2: figure 1.B -- To open the door on the drive, simply turn the
  511. door lever counter-clockwise. Take the diskette to be inserted, and
  512. place it in the drive face-up with the large opening going in first
  513. and write-protect notch to the left (covered with tape in the
  514. demonstration disk) (see figure 4).
  515.  
  516. Close the drive door by turning clockwise direction until the latch
  517. clicks into place.  Now you are ready to begin working with the disk.
  518.  
  519. Remember to always remove the diskette before the drive is turned off
  520. or on. Never remove the diskette when the red drive light in on!  Data
  521. can be destroyed by the drive at this time!
  522.  
  523.  
  524.  
  525. 2.5 USING WITH A VIC 20 OR COMMODORE 64
  526.  
  527. The 1541 Disk Drive can work with either the VIC 20 or Commodore 64
  528. computers.  However, each computer has different requirements for
  529. speed of incoming data.  Therefore, there is a software switch for
  530. selecting which computer's speed to use. The drive starts out ready
  531. for a Commodore 64.  To switch to VIC 20 speed, the following command
  532. must be sent after the drive is started (power-on or through
  533. software):
  534.  
  535.    OPEN 15, 8, 15, "UI-": CLOSE 15
  536.  
  537. To return the disk drive to Commodore 64 speed, use this command:
  538.  
  539.    OPEN 15, 8, 15, "UI+": CLOSE 15
  540.  
  541. More about using this type of command is in chapter 4, with a detailed
  542. explanation of the U (user) commands in chapter 8.
  543.  
  544.  
  545.  
  546. 3. USING PROGRAMS
  547.  
  548. 3.1 LOADING PREPACKAGED PROGRAMS
  549.  
  550. For those of you interested in using only prepackaged programs
  551. available on cartridges, cassette, or disk, here's all you have to do:
  552.  
  553. Using your disk drive, carefully insert the preprogrammed disk so that
  554. the label on the disk is facing up and is closest to you.  Look for a
  555. little notch on the disk (it might be covered with a little piece of
  556. tape).  If you're inserting the disk properly, the notch will be on
  557. the left side.  Once the disk is inside, close the protective gate by
  558. pushing in on the level. Now type LOAD "PROGRAM NAME", 8 and hit the
  559. RETURN key. The disk will make noise and your screen will say:
  560.  
  561.  SEARCHING FOR PROGRAM NAME
  562.  LOADING
  563.  
  564.  READY
  565.  
  566. When the word READY appears, just type RUN, and your prepackaged
  567. software is ready to use.
  568.  
  569.  
  570.  
  571. 3.2 LOAD
  572.  
  573. The BASIC commands used with Programs on the disk drive are the same
  574. as the commands used on the Commodore DATASSETTE-tm recorder.  There
  575. are a few extra commands available for use with disks, however.
  576.  
  577. First of all, the program name must be given with each command.  On a
  578. DATASSETTE-tm, you could omit the program name in order to just LOAD
  579. the first program there.  On disk, since there are many different
  580. programs that are equally accessible, the program name must be used to
  581. tell the disk drive what to do.  In addition, the disk drive's device
  582. number must be specified.  If no device number is listed, the computer
  583. assumes the program is on tape.
  584.  
  585. FORMAT FOR THE LOAD COMMAND:
  586.  
  587.    LOAD name$, device#, command#
  588.  
  589. The program name is a string, that is, either a name in quotes or the
  590. contents of a given string variable.  Some valid names are: "HELLO",
  591. "PROGRAM #1", A$, NAME$.
  592.  
  593. The device# is preset on the circuit board to be #8.  If you have more
  594. than one drive, see chapter 9 on how to change the device number. This
  595. book assumes that you're using device number 8 for the disk drive.
  596.  
  597. The command# is optional.  If not given, or zero, the program is
  598. LOADed normally, that is, beginning at the start of your available
  599. memory for BASIC programs.  If the number is 1, the program will be
  600. LOADed at exactly the same memory locations from which it came.  In
  601. the case of computers with different memory configurations, like VICs
  602. with 5K, 8K, or more memory, the start of BASIC memory is in different
  603. places.  The command# 0 permits BASIC programs to LOAD normally.
  604. Command# 1 is used mainly for machine language, character sets, and
  605. other memory dependent functions.
  606.  
  607. EXAMPLES
  608.  
  609.    LOAD "TEST", 8
  610.    LOAD "Program # 1", 8
  611.    LOAD A$, J, K
  612.    LOAD "Mach Lang", 8, 1
  613.  
  614. NOTE: You can use variables to represent device numbers, commands, and
  615. strings, as long as you've previously defined them in your program.
  616.  
  617.  
  618.  
  619. 3.3 DIRECTORY OF DISKETTE
  620.  
  621. The DATASSETTE-tm tape deck is a sequential device.  It can only read
  622. from the beginning of the tape to the end, without skipping around the
  623. tape and without the capability of going backward or recording over
  624. old data.
  625.  
  626. Your disk drive is a random access device.  The read/write head of the
  627. disk can go to any spot on the disk and access a single block of data
  628. which holds up to 256 bytes of information.  There are a total of 683
  629. blocks on a single diskette.
  630.  
  631. Fortunately, you don't really have to worry about individual blocks of
  632. data. There is a progrmn in the disk drive called the Disk Operating
  633. System, or the DOS. This program keeps track of the blocks for you. It
  634. organizes them into a Block Availability Map, or BAM, and a directory.
  635.  
  636. The Block Availability Map is simply a checklist of all 683 blocks on
  637. the disk.  It is stored in the middle of the diskette, halfway between
  638. the center hub and the outer rim. Every time a program is SAVED or a
  639. data file is CLOSED, the BAM is updated with the list of blocks used
  640. up.
  641.  
  642. The directory is a list of all programs and other files stored on the
  643. disk.  It is physically located right next to the BAM.  There are 144
  644. entries available in the directory, consisting of information like
  645. file name and type, a list of blocks used, and the starting block.
  646. The directory is automatically updated every time a program is SAVEd
  647. or a file is OPENed for writing.  BEWARE: the BAM isn't updated until
  648. the file is CLOSED, even though the directory changes right away.  If
  649. a file isn't CLOSED properly, all data in that file will probably be
  650. lost.
  651.  
  652. The directory can be LOADed into your memory just like a BASIC program.
  653. Place the diskette in the drive, and type the following command:
  654.  
  655.  LOAD "$", 8
  656.  
  657. The computer responds with:
  658.  
  659.  SEARCHING FOR $
  660.  
  661.  FOUND $
  662.  
  663.  LOADING
  664.  
  665.  READY.
  666.  
  667. Now the directory is in your computer's memory.  Type LIST, and you'll
  668. see the directory displayed on the screen.  To print the directory on
  669. your printer, type the following command line (in this example your
  670. printer is plugged in as device# 4):
  671.  
  672.    OPEN 4, 4: CMD 4: LIST
  673.  
  674. NOTE: When using CMD, the file must be closed using the command
  675. PRINT#4: CLOSE 4. See the VIC 1525/1515 printer manual for detailed
  676. explanation.
  677.  
  678. To read the directory without LOADing it into your memory, see the
  679. section later in this chapter on the DOS Support Program.  In addition,
  680. to examine the directory from inside a BASIC program, see the section
  681. in chapter 5 that deals with the GET# statement.
  682.  
  683.  
  684.  
  685. 3.4 PATTERN MATCHING AND WILD CARDS
  686.  
  687. When using the tape deck, you can LOAD any program starting with
  688. certain letters just by leaving off any following letters.  Thus, the
  689. command LOAD "T" will find the first program on the tape beginning
  690. with the letter T. And LOAD "HELLO" will find the first program
  691. beginning with the letters HELLO, like "HELLO THERE."
  692.  
  693. When using the disk, this option is called pattern matching, and there
  694. is a special character in the file name used to designate this.  The
  695. asterisk (*) character following any program name tells the drive you
  696. want to find any program starting with that name.
  697.  
  698. FORMAT FOR PATTERN MATCHING:
  699.                   +-------------------+
  700.  LOAD name$ + "*", 8          | Can Be a String   |
  701.      |                    | Variable Or The   |
  702.      +--------------------+ Name Inside Quotes|
  703.                   +-------------------+
  704.  
  705. In other words, if you want to LOAD the first program on the disk
  706. starting with the letter T, use the command LOAD "T*", 8.
  707.  
  708. If only the "*" is used for the name, the last program accessed on the
  709. disk is the one LOADed.  If no program has yet been LOADed, the first
  710. one listed in the directory is the one used.
  711.  
  712. You are probably familiar with the concept of wild cards in poker
  713. where one card can replace any other card needed.  On your 1541, the
  714. question mark (?) can be used as a wild card on the disk.  The program
  715. name on the disk is compared to the name in the LOAD command, but any
  716. characters where there is a question mark in the name aren't checked.
  717.  
  718. For instance, when the command LOAD "T?NT", 8 is given, programs that
  719. match include TINT, TENT, etc.
  720.  
  721. When LOADing the directory of the disk, pattern matching and wild
  722. cards can be used to check for a list of specific programs.  If you
  723. gave the command LOAD "$0:TEST", only the program TEST would appear in
  724. the directory (if present on the disk).  The command LOAD "$0:T*"
  725. would give you a directory of all programs beginning with the letter T.
  726. And LOAD "$0:T?ST" would give you all the programs with 4-letter names
  727. having the first letter of T and the third and fourth letters ST. LOAD
  728. "$0:T?ST*" would give names of any length with the correct first,
  729. third, and fourth letters.
  730.  
  731.  
  732.  
  733. 3.5 SAVE
  734.  
  735. To SAVE a program to the diskette, all that is needed is to add the
  736. device number after the program name.  Just like the SAVE command for
  737. the tape deck, the device number can be followed by a command number,
  738. to prevent the automatic re-location on LOADing (see the section on
  739. the LOAD command, above).
  740.  
  741. FORMAT FOR THE SAVE COMMAND:
  742.  
  743.    SAVE name$, device#, command#
  744.  
  745. See the LOAD command (section 3.3) for an explanation of the
  746. parameters device# and command#.
  747.  
  748. When you tell the disk drive to SAVE a program, the DOS must take
  749. several steps.  First, it looks at the directory to see if a program
  750. with that name already exists. Next it checks to see that there is a
  751. directory entry available for the name.  Then it checks the BAM to see
  752. if there are enough blocks in which to store the program.  If
  753. everything is OK up to this point, the program is stored.  If not, the
  754. error light will flash.
  755.  
  756.  
  757.  
  758. 3.6 SAVE AND REPLACE
  759.  
  760. If a program already exists on the disk, it is often necessary to make
  761. a change and re-SAVE it onto the disk.  In this case, it would be
  762. inconvenient to have to erase the old version of the program and then
  763. SAVE it.
  764.  
  765. If the first characters of the program name are the "@" sign followed
  766. by a 0 and a colon (:), the DOS knows to replace any old program that
  767. has that name with the program that is now in the computer's memory.
  768. The drive checks the directory to find the old program, then it marks
  769. that entry as deleted, and it next creates a new entry with the same
  770. name.  Finally, the program is stored normally.
  771.  
  772. FORMAT FOR SAVE WITH REPLACE:
  773.  
  774.    SAVE "@0:" + name$, device#, command#
  775.  
  776. For example, if a file was called TEST, the SAVE and replace command
  777. would be SAVE "@0:TEST",8.  If the name is in A$, the command is SAVE
  778. "@0:" + A$, 8.
  779.  
  780. The reason for the 0: is to keep compatibility with other Commodore
  781. disk drive units which have more than one drive built in.  In that
  782. case, the number 0 or 1 is used to specify which drive is being used.
  783.  
  784.  
  785.  
  786. 3.7 VERIFY
  787.  
  788. The VERIFY command works to check the program currently in memory
  789. against the program on disk.  You must include a device# with the
  790. VERIFY command.  The computer does a byte-by-byte comparison of the
  791. program, including line links -- which may be different for different
  792. memory configurations.  For instance, if a program was SAVED to disk
  793. from a 5K VIC 20, and re-LOADed on an 8K machine, it wouldn't VERIFY
  794. properly because the links point to different memory locations.
  795.  
  796. FORMAT FOR VERIFY COMMAND:
  797.  
  798.    VERIFY name$, device#
  799.  
  800.  
  801.  
  802. 3.8 DOS SUPPORT PROGRAM
  803.  
  804. On your demonstration disk, there may be a program called DOS SUPPORT.
  805. This program, also called a wedge, allows you to use many disk
  806. commands more easily (different wedges are used for the VIC 20 and the
  807. Commodore 64).  Just LOAD the program and RUN it.  It automatically
  808. sets itself up and erases itself when it's finished. You'll have a few
  809. hundred less bytes to work with when this program is running, but
  810. you'll also have a handy way to send the disk commands.
  811.  
  812. As a result of the DOS Support, the "/" key now takes the place of the
  813. LOAD command.  Just hit the slash followed by the progrwn name, and
  814. the program is LOADed.  When you use this method, you don't need to
  815. use the LOAD command or the comma 8.
  816.  
  817. The "@" and ">" keys are used to send commands to the disk drive. If
  818. you type @$ (or > $), the directory of the disk is displayed on the
  819. screen, without LOADing into your memory!  These keys also take the
  820. place of the PRINT# (see chapter 4) to send commands listed in the
  821. next chapter.
  822.  
  823. To read the error channel of the disk (when the red error light is
  824. blinking), just hit either the @ or the > and hit RETURN Key.  The
  825. complete error message is displayed to you: message number, text, and
  826. track and block numbers.
  827.  
  828.  
  829.  
  830. 4. DISK COMMANDS
  831.  
  832. 4.1 OPEN AND PRINT #
  833.  
  834. Up 'til now, you have explored the simple ways of dealing with the
  835. disk drive.  In order to communicate with the disk drive more fully,
  836. you have to touch on the OPEN and PRINT# statements in BASIC (more
  837. details of these commands are available in your VIC 20 or Commodore 64
  838. User's Guide or Programmer's Reference Guide).  You may be familiar
  839. with their use with data files on cassette tape, where the OPEN
  840. statement creates the file and the PRINT# statement fills the file
  841. with data. They can be used the same way with the disk, as you will
  842. see in the next chapter.  But they can also be used to set up a
  843. command channel. The command channel lets you exchange information
  844. between the computer and the disk drive.
  845.  
  846. FORMAT FOR THE OPEN STATEMENT:
  847.  
  848.    OPEN file#, device#, channel#, text$
  849.  
  850. The file# can be any number from 1 to 255.  This number is used
  851. throughout the program to identify which file is being accessed.  But
  852. numbers greater than 127 should be avoided, because they cause the
  853. PRINT# statement to generate a linefeed after the return character.
  854. These numbers are really meant to be used with non-standard printers.
  855.  
  856. The device# of the disk is usually 8.
  857.  
  858. The channel# can be any number from 2 to 15.  These refer to a channel
  859. used to communicate with the disk, and channels numbered 0 and 1 are
  860. reserved for the operating system to use for LOADing and SAVEing.
  861. Channels 2 through 14 can be used for data to files, and 15 is the
  862. command channel.
  863.  
  864. The text$ is a string that is PRINTed to the file, as if with a PRINT#
  865. statement. This is handy for sending a single command to the channel.
  866.  
  867. EXAMPLES OF OPEN STATEMENTS:
  868.  
  869.    OPEN 15, 8, 15
  870.    OPEN 2, 8, 2
  871.  
  872.     +-------------- FILE#
  873.     |  +----------- DEVICE#
  874.     |  |  +-------- COMMAND CHANNEL#
  875.     |  |  |
  876.    OPEN A, B, C, Z$
  877.          |
  878.          +----- COMMAND$(text$)
  879.  
  880. The PRINT# command works exactly like a PRINT statement, except that
  881. the data goes to a device other than the screen, in this case to the
  882. disk drive.  When used with a data channel, the PRINT# sends
  883. information into a buffer in the disk drive, which LOADs it onto the
  884. diskette.  When PRINT# is used with the command channel, it sends
  885. commands to the disk drive.
  886.  
  887. FORMAT FOR SENDING DISK COMMANDS:
  888.  
  889.    OPEN 15, 8, 15, command$
  890.  
  891. or
  892.  
  893.    PRINT# 15, command$
  894.  
  895.  
  896.  
  897. 4.2 NEW
  898.  
  899. This command is necessary when using a diskette for the first time.
  900. The NEW command erases the entire diskette, it puts timing and block
  901. markers on the diskette and creates the directory and BAM.  The NEW
  902. command can also be used to clear out the directory of an already-
  903. formatted diskette.  This is faster than re-formatting the whole disk.
  904.  
  905. FORMAT FOR THE NEW COMMAND TO FORMAT DISK:
  906.  
  907.    PRINT#15, "NEW:name,id"
  908.  
  909. or abbreviated as
  910.  
  911.    PRINT#15, "N:name,id"
  912.  
  913. FORMAT FOR THE NEW COMMAND TO CLEAR DIRECTORY:
  914.  
  915.    PRINT#15, "N:name"
  916.  
  917. The name goes in the directory as the name of the entire disk.  This
  918. only appears when the directory is listed.  The ID code is any 2
  919. characters, and they are placed not only on the directory but on every
  920. block throughout the diskette.  That way, if you carelessly replace
  921. diskettes while writing data, the drive will know by checking the ID
  922. that something is wrong.
  923.  
  924.  
  925.  
  926. 4.3 COPY
  927.  
  928. This command allows you to make a copy of any program or file on the
  929. disk drive.  It won't copy from one drive to a different one (except
  930. in the case of dual drives like the 4040), but it can duplicate a
  931. program under another name on the drive.
  932.  
  933. FORMAT FOR THE COPY COMMAND:
  934.  
  935.    PRINT# 15, "COPY:newfile=oldfile"
  936.  
  937. or abbreviated as
  938.  
  939.    PRINT# 15, "C:newfile=oldfile"
  940.  
  941. The COPY command can also be used to combine two through four files on
  942. the disk.
  943.  
  944. FORMAT FOR COPY TO COMBINE FILES:
  945.  
  946.  PRINT# 15, "C:newfile=oldfile1,oldfile2,oldfile3,oldfile4"
  947.  
  948. EXAMPLES OF COPY COMMAND:
  949.  
  950.    PRINT# 15, "C:BACKUP=ORIGINAL"
  951.    PRINT# 15, "C:MASTERFILE=NAME,ADDRESS,PHONES"
  952.  
  953.  
  954.  
  955. 4.4 RENAME
  956.  
  957. This command allows you to change the name of a file once it is in the
  958. disk directory.  This is a fast operation, since only the name in the
  959. directory must be changed.
  960.  
  961. FORMAT FOR RENAME COMMAND:
  962.  
  963.    PRINT# 15, "RENAME:newname=oldname"
  964.  
  965. or abbreviated as
  966.  
  967.    PRINT# 15, "R:newname=oldname"
  968.  
  969. EXAMPLE OF RENAME COMMAND:
  970.  
  971.    PRINT#15, "R:MYRA=MYRON"
  972.  
  973. The RENAME command will not work on any files that are currently OPEN.
  974.  
  975.  
  976.  
  977. 4.5 SCRATCH
  978.  
  979. This command allows you to erase unwanted files and programs from the
  980. disk, which then makes the blocks available for new information.  You
  981. can erase programs one at a time or in groups by using pattem matching
  982. and or wild cards.
  983.  
  984. FORMAT FOR SCRATCH COMMAND
  985.  
  986.    PRINT# 15, "SCRATCH:name"
  987.  
  988. or abbreviated as
  989.  
  990.    PRINT# 15, "S:name"
  991.  
  992. If you check the error channel after a scratch operation (see below),
  993. the number usually reserved for the track number now tells you how
  994. many files were scratched.  For example, if your directory contains
  995. the programs KNOW and GNAW, and you use the command PRINT# 15,
  996. "S:?N?W", you will scratch both programs.  If the directory contains
  997. TEST, TRAIN, TRUCK, and TAIL, and you command the disk to PRINT# 15,
  998. "S:T*", you will erase all four of these programs.
  999.  
  1000.  
  1001.  
  1002. 4.6 INITIALIZE
  1003.  
  1004. At times, an error condition on the disk will prevent you from
  1005. performing some operation you want to do.  The INITIALIZE command
  1006. returns the disk drive to the same state as when powered up.  You must
  1007. be careful to re-match the drive to the computer (see chapter 2).
  1008.  
  1009. FORMAT FOR INITIALIZE COMMAND:
  1010.  
  1011.    PRINT# 15, "INITIALIZE"
  1012.  
  1013. or abbreviated as
  1014.  
  1015.    PRINT# 15, "I"
  1016.  
  1017.  
  1018.  
  1019. 4.7 VALIDATE
  1020.  
  1021. After a diskette has been in use for some time, the directory can
  1022. become disorganized.  When programs have been repeatedly SAVED and
  1023. SCRATCHed, they may leave numerous small gaps on the disk, a block
  1024. here and a few blocks there.  These blocks never get used because they
  1025. are too small to be useful.  The VALIDATE command will go in and re-
  1026. organize your diskette so that you can get the most from the available
  1027. space.
  1028.  
  1029. Also, there may be data files that were OPENed but never properly
  1030. CLOSED. This command will collect all blocks taken by such files and
  1031. make them available to the drive, since the files are unusable at that
  1032. point.
  1033.  
  1034. There is a danger in using this command.  When using random files (see
  1035. chapter 6), blocks allocated will be de-allocated by this command.
  1036. Therefore, this command should never be used with a diskette that uses
  1037. random files.
  1038.  
  1039. FORMAT FOR VALIDATE COMMAND:
  1040.  
  1041.    PRINT#15, "VALIDATE"
  1042.  
  1043. or abbreviated as
  1044.  
  1045.    PRINT#15, "V"
  1046.  
  1047.  
  1048.  
  1049. 4.8 DUPLICATE
  1050.  
  1051. This command is a hangover from the operating systems that were
  1052. contained on the dual drives like the 4040. It was used to copy entire
  1053. diskettes from one drive to another, but has no function on a single
  1054. disk drive.
  1055.  
  1056.  
  1057.  
  1058. 4.9 READING THE ERROR CHANNEL
  1059.  
  1060. Without the DOS Support Program, there is no way to read the disk
  1061. error channel without a program, since you need to use the INPUT#
  1062. command which won't work outside a program.  Here is a simple BASIC
  1063. routine to read the error channel:
  1064.  
  1065.  10 OPEN 15, 8, 15
  1066.  20 INPUT# 15, A$, B$, C$, D$
  1067.  30 PRINT A$, B$, C$, D$
  1068.  
  1069. Whenever you perform an INPUT# operation from the command channel, you
  1070. read up to 4 variables that describe the error condition.  The first,
  1071. third, and fourth variables come in as numbers, and can be INPUT into
  1072. numeric variables if you like. The first variable describes the
  1073. error#$, where 0 is no error.  The second variable is the error
  1074. description. The third variable is the track number on which the error
  1075. occurred, and the fourth and final is the block number inside that
  1076. track. (A block is also known as a sector)
  1077.  
  1078. Errors on track 18 have to do with the BAM and directory.  For example,
  1079. a READ ERROR on track 18 block 0 may indicate that the disk was never
  1080. formatted.
  1081.  
  1082.  
  1083.  
  1084. 4.10 CLOSE
  1085.  
  1086. It is extremely important that you properly CLOSE files once you are
  1087. finished using them. Closing the file causes DOS to properly allocate
  1088. blocks in the BAM and to finish the entry in the directory. If you
  1089. don't CLOSE the file, all your data will be lost!
  1090.  
  1091. FORMAT FOR CLOSE STATEMENT:
  1092.  
  1093.  CLOSE file#
  1094.  
  1095. You should also be careful not to CLOSE the error channel (channel#
  1096. 15) before CLOSEing your data channels.  The error channel should be
  1097. OPENed first and CLOSEd last of all your files! That will keep your
  1098. programs out of trouble.
  1099.  
  1100. If you close the error channel while other files are OPEN, the disk
  1101. drive will close them for you, but BASIC will still think they are
  1102. open (unless you CLOSE them properly), let you to try to write to them.
  1103.  
  1104.  
  1105. NOTE: If your BASIC program leads you into an effor condition, all
  1106. files are CLOSEd in BASIC, without CLOSEing them on your disk drive!
  1107. This is a very dangerous condition. You should immediately type the
  1108. statement OPEN 15, 8, 15, "I". This will re-initialize your drive and
  1109. make all your files safe.
  1110.  
  1111.  
  1112.  
  1113. 5. SEQUENTIAL FILES
  1114.  
  1115. 5.1 OPEN
  1116.  
  1117. SEQuential files are limited by their sequential nature, which means
  1118. they must be read from beginning to end.  Data is transferred byte by
  1119. byte, through a buffer, onto the magnetic media.  To the disk drive
  1120. all files are created equal.  That is, SEQuential files, program files,
  1121. and user files all work the same on the disk.  Only program files can
  1122. be LOADed, but that's really the only difference.  Even the directory
  1123. works like this, except that it is read-only.  The only difference is
  1124. with relative files.
  1125.  
  1126. FORMAT FOR OPENING A SEQUENTIAL FILE:
  1127.  
  1128.    OPEN file#, device#, channel#, "0:name,type,direction"
  1129.  
  1130. The file number is the same as in all your other applications of the
  1131. OPEN statement, and it is used throughout the program to refer to this
  1132. particular file.  The device# is usually 8. The channel# is a data
  1133. channel, number 2 through 14.  It is convenient to use the same number
  1134. for both the channel# and file#, to keep them straight.  The name is
  1135. the file name (no wild cards or pattern matching if you're creating a
  1136. write file).  The type can be any of the ones from the chart below, at
  1137. least the first letter of each type. The direction must be READ or
  1138. WRITE, or at least the first letter of each.
  1139.  
  1140.  
  1141.  FILE TYPE   MEANING
  1142.  
  1143.  PRG         Program
  1144.  SEQ         Sequential
  1145.  USR         User
  1146.  REL         Relative
  1147.  
  1148. EXAMPLES OF OPENING SEQUENTIAL FILES:
  1149.  
  1150.    OPEN 2, 8, 2, "0:DATA, S, W"
  1151.    OPEN 8, 8, 8, "0:Program, P, R"
  1152.    OPEN A, B, C, "0:" + A$ + "U,W"
  1153.  
  1154. If the file already exists, you can use the replace option in the OPEN
  1155. statement, similar to the SAVE-and-replace described in chapter 3.
  1156. Simply add the @0: before the file's name in the OPEN statement.
  1157.  
  1158. EXAMPLE OF SEQUENTIAL FILE WITH REPLACE OPTION:
  1159.  
  1160.    OPEN 2, 8, 2, "@0:DATA,S,W"
  1161.  
  1162. The 0: should always precede the name of the file or the drive will
  1163. only allow you to use 2 of the available buffers.
  1164.  
  1165.  
  1166.  
  1167. 5.2 PRINT# and INPUT#
  1168.  
  1169. The PRINT# command works exactly like the PRINT statement, except that
  1170. output is re-directed to the disk drive.  The reason for the special
  1171. emphasis on the word exactly is that all the formatting capabilities
  1172. of the PRINT statement, as applies to punctuation and data types,
  1173. applies here too.  It just means that you have to be careful when
  1174. putting data into your files.
  1175.  
  1176. FORMAT FOR WRITING TO FILE WITH PRINT#:
  1177.  
  1178.    PRINT# file#, data list
  1179.  
  1180. The file# is the one from the OPEN statement when the file was created.
  1181.  
  1182.  
  1183. The data list is the same as the regular PRINT statement -- a list of
  1184. variables and/or text inside quote marks.  However, you must be
  1185. especially careful when writing data so that it is as easy as possible
  1186. to read the data back again.
  1187.  
  1188. When using the PRINT# statement, if you use commas (,) to separate
  1189. items on the fine, the items will be separated by some blank spaces,
  1190. as if it were being formatted for the screen.  Semicolons (;) don't
  1191. result in any extra spaces.
  1192.  
  1193. In order to more fully understand what's happening, here is a diagram
  1194. of a sequential file created by the statement OPEN 5, 8, 5,
  1195. "0:TEST,S,W":
  1196.  
  1197.       |eof|   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  1198.  -----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
  1199.  char | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| 14| 15|...
  1200.  
  1201. The eof stands for the end-of-file marker.  String data entering the
  1202. file goes in byte by byte, including spaces.
  1203.  
  1204. For instance, let's set up some variables with the statement A$=
  1205. "HELLO"; B$ = "ALL": C$ = "BYE". Here is a picture of a file after the
  1206. statement PRINT# 5, A$; B$; C$:
  1207.  
  1208.       | H | E | L | L | O | A | L | L | B | Y | E | CR|eof|
  1209.  -----+---+---+---+---+---+---+---+---+---+---+---+---+---+
  1210.  char | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13|
  1211.  
  1212. CR stands for the CHR$ code of 13, the carriage return, which is
  1213. PRINTed at the end of every PRINT or PRINT# statement unless there is
  1214. a comma or semicolon at the end of the line.
  1215.  
  1216. NOTE: Do not leave a space between PRINT and #, and do not try to
  1217. abbreviate the command as ?#.  See the appendixes in the user manual
  1218. for the correct abbreviation.
  1219.  
  1220. FORMAT FOR INPUT# STATEMENT:
  1221.  
  1222.    INPUT# file#, variable list
  1223.  
  1224. When using the INPUT# to read in data, the disk drive can't tell that
  1225. it's not supposed to be one long string.  You need something in the
  1226. file to act as a separator. Characters to use as separators include
  1227. the CR, a comma or a semicolon.  The CR can be added easily by just
  1228. using one variable per line on the PRINT# statement, and the system
  1229. puts one there automatically.  The statement PRINT# 5, A$: PRINT# 5,
  1230. B$: PRINT# 5, C$ puts a CR after every variable being written,
  1231. providing the proper separation for a statement like INPUT#5, A$, B$,
  1232. C$.  Or else a line like Z$ = ",":PRINT# 5, A$ Z$ B$ Z$ C$ will do the
  1233. job as well, and in less space.  The file after that line looks like
  1234. this:
  1235.  
  1236.       | H | E | L | L | O | , | A | L | L | , | B | Y | E | CR|eof|
  1237.  -----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  1238.  char | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| 14| 15|
  1239.  
  1240. Putting commas between variables results in lots of extra space on the
  1241. disk being used.  A statement like PRINT# 5, A$, B$ makes a file that
  1242. looks like:
  1243.  
  1244.       | H | E | L | L | O |   |   |   | A | L | L |   | CR|eof|
  1245.  -----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  1246.  char | 1 | 2 | 3 | 4 | 5 | 6 |...| 11| 12| 13| 14|...| 23| 24|
  1247.  
  1248. You can see that much of the space in the file is wasted.
  1249.  
  1250. The moral of all this is: take care when using PRINT# so your data
  1251. will be in order for reading back in.
  1252.  
  1253. Numeric data written in the file takes the form of a string, as if the
  1254. STR$ function had been performed on it before writing it out.  The
  1255. first character will be a blank space if the number is positive, and a
  1256. minus sign (-) if the number is negative.  Then comes the number, and
  1257. the last character is the cursor right character.  This format
  1258. provides enough information for the INPUT# statement to read them in
  1259. as separate numbers if several are written with no other special
  1260. separators.  It is somewhat wasteful of space, since there can be two
  1261. unused characters if the numbers are positive.
  1262.  
  1263. Here is a picture of the file after the statement PRINT# 5, 1; 3; 5; 7
  1264. is performed:
  1265.  
  1266.       |   | 1 |-->|   | 3 |-->|   | 5 |-->|   | 7 |-->| CR|eof|   |
  1267.  -----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  1268.  char | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| 14| 15|
  1269.  
  1270. Appendix B contains a program demonstrating the use of a sequential
  1271. disk file.
  1272.  
  1273.  
  1274.  
  1275. 5.3 GET#
  1276.  
  1277. The GET# retrieves data from the disk, one character at a time.
  1278.  
  1279. FORMAT FOR THE GET# STATEMENT:
  1280.  
  1281.    GET# file#, variable list
  1282.  
  1283. Data comes in byte by byte, including the CR, comma, and other
  1284. separating characters.  It is much safer to use string variables when
  1285. using the GET# statement.  You will get a BASIC error message if
  1286. string data is received where a number was requested, but not vice-
  1287. versa.
  1288.  
  1289. EXAMPLES OF GET# STATEMENT:
  1290.  
  1291.    GET# 5, A$
  1292.    GET# A, B$, C$, D$
  1293.        |   |   |
  1294.            +---+---+--- You can get more than 1 character at a time
  1295.    GET# 5, A
  1296.  
  1297. The GET# statement is extremely useful when examining files with
  1298. unknown contents, like a file that may have been damaged by an
  1299. experimental program.  It is safer than INPUT# because there is a
  1300. limit to the number of characters allowed between separators of INPUT
  1301. variables.  With GET#, you receive every character, and you can
  1302. examine separators as well as other data.
  1303.  
  1304. Here is a sample program that will allow you to examine any file on
  1305. the disk:
  1306.  
  1307. start tok64 examfile.prg
  1308.  10 input "file name";f$
  1309.  20 input "file type";t$
  1310.  30 t$ = left$ (t$,1)
  1311.  40 if t$<>"s" then if t$<>"p" then if t$<>"u" then 20
  1312.  45 open 15,8,15
  1313.  50 open 5,8,5,"0:" + f$ + "," + t$ + ",r"
  1314.  60 gosub 200
  1315.  70 get#5, a$
  1316.  80 if st=0 then 90
  1317.  85 if st=64 then close 5,15:end
  1318.  87 print st:stop
  1319.  90 print asc(a$ + chr$(0))
  1320.  100 goto 70
  1321.  200 input#15,a$,b$,c$,d$
  1322.  210 if val(a$)> 0 then printa$,b$,c$,d$:stop
  1323.  220 return
  1324. stop tok64
  1325.  
  1326. begin 644 EXAMFILE.PRG
  1327. M`0@6"`H`A2`B1DE,12!.04U%(CM&)``K"!0`A2`B1DE,12!465!%(CM4)``]
  1328. M"!X`5"0@LB#(("A4)"PQ*0!H""@`BR!4)+.Q(E,B(*<@BR!4)+.Q(E`B(*<@
  1329. MBR!4)+.Q(E4B(*<@,C``=@@M`)\@,34L."PQ-0">"#(`GR`U+#@L-2PB,#HB
  1330. M(*H@1B0@JB`B+"(@JB!4)""J("(L4B(`J`@\`(T@,C`P`+0(1@"A(S4L($$D
  1331. M`,0(4`"+(%-4LC`@IR`Y,`#;"%4`BR!35+(V-""G(*`@-2PQ-3J``.8(5P"9
  1332. M(%-4.I``^0A:`)D@QBA!)""J(,<H,"DI``()9`")(#<P`!8)R`"$,34L020L
  1333. M0B0L0R0L1"0`-@G2`(L@Q2A!)"FQ(#`@IR"9020L0B0L0R0L1"0ZD``\"=P`
  1334. $C@``````
  1335. `
  1336. end
  1337.  
  1338.  
  1339.  
  1340. 5.4 READING THE DIRECTORY
  1341.  
  1342. The directory of the diskette may be read just fike a sequential file.
  1343. Just use $ for the file name, and OPEN 5, 8, 5, "$".  Now the GET#
  1344. statement works to examine the directory.  The format here is
  1345. identical to the format of a program file: the file sizes are the line
  1346. numbers, and names are stored as characters within quote marks.
  1347.  
  1348. Here's a program that lets you read the directory of the diskette:
  1349.  
  1350. start tok64 readdir.prg
  1351.  10 open 1,8,2,"$"
  1352.  20 for x=1 to 141:get#1,a$:next:rem skip over bam
  1353.  30 t$(0)="del":t$(1)="seq":t$(2)="prg":t$(3)="usr":t$(4)="rel"
  1354.  40 j=17:gosub 500:rem disk name
  1355.  50 n$=b$
  1356.  60 j=2:rem set length of id string
  1357.  70 gosub 500
  1358.  80 i$=b$
  1359.  85 get#1,a$
  1360.  90 j=2:rem set length of operating system string
  1361.  100 gosub 500
  1362.  110 o$=b$
  1363.  120 for l=1 to 88
  1364.  130 get#1,a$:rem get rest of block
  1365.  140 next
  1366.  160 print chr$(147) "disk name:"n$,"id:"i$,"os:"o$
  1367.  161 print "length","type","name"
  1368.  165 for p=1 to 8
  1369.  170 get#1,t$,a$,a$:rem file type
  1370.  180 if t$="" then t$ = chr$(128)
  1371.  190 j=15:rem set length of file name string
  1372.  200 gosub 500
  1373.  210 n$=b$
  1374.  220 get#1,a$,a$,a$,a$,a$,a$,a$,a$,a$,l$,h$:rem low & high bytes \
  1375.      of file length
  1376.  225 l=asc(l$+chr$(0))+256*asc(h$+chr$(0)):if l=0 then 260
  1377.  227 if st then close 1:end
  1378.  230 print l,t$(asc(t$)-128),n$
  1379.  250 if p < 8 then get#1,a$,a$
  1380.  260 next p:goto 165
  1381.  500 b$="":rem string building routine
  1382.  510 for l=0 to j
  1383.  520 get#1,a$
  1384.  530 if a$<>chr$(96) then if a$<>chr$(160) then b$=b$ + a$
  1385.  540 next
  1386.  550 return
  1387. stop tok64
  1388.  
  1389. begin 644 READDIR.PRG
  1390. M`0@1"`H`GR`Q+#@L,BPB)"(`.@@4`($@6+(Q(*0@,30Q.J$C,2Q!)#J".H\@
  1391. M4TM)4"!/5D52($)!30!Z"!X`5"0H,"FR(D1%3"(Z5"0H,2FR(E-%42(Z5"0H
  1392. M,BFR(E!21R(Z5"0H,RFR(E534B(Z5"0H-"FR(E)%3"(`E0@H`$JR,3<ZC2`U
  1393. M,#`ZCR!$25-+($Y!344`GP@R`$XDLD(D`,$(/`!*LC(ZCR!3150@3$5.1U1(
  1394. M($]&($E$(%-44DE.1P#+"$8`C2`U,#``U0A0`$DDLD(D`.`(50"A(S$L020`
  1395. M$`E:`$JR,CJ/(%-%5"!,14Y'5$@@3T8@3U!%4D%424Y'(%-94U1%32!35%))
  1396. M3D<`&@ED`(T@-3`P`"0);@!/)+)")``S"7@`@2!,LC$@I"`X.`!2"8(`H2,Q
  1397. M+$$D.H\@1T54(%)%4U0@3T8@0DQ/0TL`6`F,`((`A`F@`)D@QR@Q-#<I(")$
  1398. M25-+($Y!344Z(DXD+"))1#HB220L(D]3.B)/)`"A":$`F2`B3$5.1U1((BPB
  1399. M5%E012(L(DY!344B`*\)I0"!(%"R,2"D(#@`S`FJ`*$C,2Q4)"Q!)"Q!)#J/
  1400. M($9)3$4@5%E010#F";0`BR!4)+(B(B"G(%0D(+(@QR@Q,C@I`!`*O@!*LC$U
  1401. M.H\@4T54($Q%3D=42"!/1B!&24Q%($Y!344@4U1224Y'`!H*R`"-(#4P,``D
  1402. M"M(`3B2R0B0`;@K<`*$C,2Q!)"Q!)"Q!)"Q!)"Q!)"Q!)"Q!)"Q!)"Q!)"Q,
  1403. M)"Q()#J/($Q/5R`F($A)1T@@0EE415,@3T9&24Q%($Q%3D=42`":"N$`3++&
  1404. M*$PDJL<H,"DIJC(U-JS&*$@DJL<H,"DI.HL@3+(P(*<@,C8P`*L*XP"+(%-4
  1405. M(*<@H"`Q.H``Q`KF`)D@3"Q4)"C&*%0D*:LQ,C@I+$XD`-P*^@"+(%`@LR`X
  1406. M(*<@H2,Q+$$D+$$D`.H*!`&"(%`ZB2`Q-C4`#@OT`4(DLB(B.H\@4U1224Y'
  1407. M($)524Q$24Y'(%)/551)3D4`'`O^`8$@3+(P(*0@2@`G"P@"H2,Q+$$D`%,+
  1408. M$@*+($$DL[''*#DV*2"G((L@022SL<<H,38P*2"G($(DLD(D(*H@020`60L<
  1409. +`H(`7PLF`HX`````
  1410. `
  1411. end
  1412.  
  1413.  
  1414.                  Table 5.1: 1540/1541 BAM FORMAT
  1415.  +-----------------------------------------------------------------+
  1416.  | Track 18, Sector 0.                                             |
  1417.  +-------+----------+----------------------------------------------+
  1418.  | BYTE  | CONTENTS |                DEFINITION                    |
  1419.  +-------+----------+----------------------------------------------+
  1420.  | 0,1   | 18,01    | Track and sector of first directory block.   |
  1421.  +-------+----------+----------------------------------------------+
  1422.  | 2     | 65       | ASCII character A indicating 4040 format.    |
  1423.  +-------+----------+----------------------------------------------+
  1424.  | 3     | 0        | Null flag for future DOS use.                |
  1425.  +-------+----------+----------------------------------------------+
  1426.  | 4-143 |          | Bit map of available blocks for tracks 1-35. |
  1427.  +-------+----------+----------------------------------------------+
  1428.  | *1 = available block                                            |
  1429.  |  0 = block not available                                        |
  1430.  |      (each bit represents one block)                            |
  1431.  +-----------------------------------------------------------------+
  1432.  
  1433.  
  1434.                  Table 5.2: 1540/1541 DIRECTORY HEADER
  1435.  +-----------------------------------------------------------------+
  1436.  | Track 18, Sector 0.                                             |
  1437.  +---------+----------+--------------------------------------------+
  1438.  | BYTE    | CONTENTS |              DEFINITION                    |
  1439.  +---------+----------+--------------------------------------------+
  1440.  | 144-161 |          | Disk name padded with shifted spaces.      |
  1441.  +---------+----------+--------------------------------------------+
  1442.  | 162-163 |          | Disk ID.                                   |
  1443.  +---------+----------+--------------------------------------------+
  1444.  | 164     | 160      | Shifted space.                             |
  1445.  +---------+----------+--------------------------------------------+
  1446.  | 165,166 | 50,65    | ASCII representation for 2A which is DOS   |
  1447.  |         |          | version and format type.                   |
  1448.  +---------+----------+--------------------------------------------+
  1449.  | 166-167 | 160      | Shifted spaces.                            |
  1450.  +---------+----------+--------------------------------------------+
  1451.  | 171-255 | 0        | Nulls, not used.                           |
  1452.  +---------+----------+--------------------------------------------+
  1453.  | Note: ASCII characters may appear in locations 180 thru 191 on  |
  1454.  |       some diskettes.                                           |
  1455.  +-----------------------------------------------------------------+
  1456.  
  1457.  
  1458.                  Table 5.3: DIRECTORY FORMAT
  1459.  +---------------------------------------------------------+
  1460.  | Track 18, Sector 1 for 1540/1541                        |
  1461.  +---------+-----------------------------------------------+
  1462.  | BYTE    |               DEFINITION                      |
  1463.  +---------+-----------------------------------------------+
  1464.  | 0,1     | Track and sector of next directory block.     |
  1465.  +---------+-----------------------------------------------+
  1466.  | 2-31    | *File entry 1                                 |
  1467.  +---------+-----------------------------------------------+
  1468.  | 34-63   | *File entry 2                                 |
  1469.  +---------+-----------------------------------------------+
  1470.  | 66-95   | *File entry 3                                 |
  1471.  +---------+-----------------------------------------------+
  1472.  | 98-127  | *File entry 4                                 |
  1473.  +---------+-----------------------------------------------+
  1474.  | 130-159 | *File entry 5                                 |
  1475.  +---------+-----------------------------------------------+
  1476.  | 162-191 | *File entry 6                                 |
  1477.  +---------+-----------------------------------------------+
  1478.  | 194-223 | *File entry 7                                 |
  1479.  +---------+-----------------------------------------------+
  1480.  | 226-255 | *File entry 8                                 |
  1481.  +---------+-----------------------------------------------+
  1482.  
  1483. *STRUCTURE OF SINGLE DIRECTORY ENTRY
  1484.  
  1485.  +---------+----------+--------------------------------------------+
  1486.  | BYTE    | CONTENTS |              DEFINITION                    |
  1487.  +---------+----------+--------------------------------------------+
  1488.  | 0       | 128+type | File type OR'ed with $80 (hexadecimal) to  |
  1489.  |         |          | indicate properly closed file.             |
  1490.  |         |          | TYPES: 0 = DELeted                         |
  1491.  |         |          |        1 = SEQential                       |
  1492.  |         |          |        2 = PROGram                         |
  1493.  |         |          |        3 = USER                            |
  1494.  |         |          |        4 = RELative                        |
  1495.  +---------+----------+--------------------------------------------+
  1496.  | 1,2     |          | Track and sector of 1st data block.        |
  1497.  +---------+----------+--------------------------------------------+
  1498.  |         |          | File name padded with shifted spaces.      |
  1499.  +---------+----------+--------------------------------------------+
  1500.  |         |          | Relative file only: track and sector for   |
  1501.  |         |          | first side sector block.                   |
  1502.  +---------+----------+--------------------------------------------+
  1503.  |         |          | Relative file only: Record size.           |
  1504.  +---------+----------+--------------------------------------------+
  1505.  |         |          | Unused.                                    |
  1506.  +---------+----------+--------------------------------------------+
  1507.  |         |          | Track and sector of replacement file when  |
  1508.  |         |          | OPEN@ is in effect.                        |
  1509.  +---------+----------+--------------------------------------------+
  1510.  |         |          | Number of blocks in file: low byte, high   |
  1511.  |         |          | byte.                                      |
  1512.  +---------+----------+--------------------------------------------+
  1513.  
  1514.  
  1515.                  Table 5.4: SEQUENTIAL FORMAT
  1516.  +---------+-------------------------------------------------------+
  1517.  | BYTE    |              DEFINITION                               |
  1518.  +---------+-------------------------------------------------------+
  1519.  | 0,1     | Track and sector of next sequential data block.       |
  1520.  +---------+-------------------------------------------------------+
  1521.  | 2-256   | 254 bytes of data with carriage returns as record     |
  1522.  |         | terminators.                                          |
  1523.  +---------+-------------------------------------------------------+
  1524.  
  1525.  
  1526.                  Table 5.5: PROGRAM FILE FORMAT
  1527.  +---------+-------------------------------------------------------+
  1528.  | BYTE    |              DEFINITION                               |
  1529.  +---------+-------------------------------------------------------+
  1530.  | 0,1     | Track and sector of next block in program file.       |
  1531.  +---------+-------------------------------------------------------+
  1532.  | 2-256   | 254 bytes of program info stored in CBM memory format |
  1533.  |         | (with key words tokenized).  End of file is marked by |
  1534.  |         | three zero bytes.                                     |
  1535.  +---------+-------------------------------------------------------+
  1536.  
  1537.  
  1538.  
  1539. 6. RANDOM FILES
  1540.  
  1541. [ 6.1 Explanation ]
  1542.  
  1543. Sequential files are fine when you're just working with a continuous
  1544. stream of data, but some jobs require more than that.  For example,
  1545. with a large mailing list, you would not want to have to scan through
  1546. the entire list to find a person's record.  For this you need some
  1547. kind of random access method, some way to get to any record inside a
  1548. file without having to read through the entire file first.
  1549.  
  1550. There are actually two different types of random access files on the
  1551. Commodore disk drive.  The relative files discussed in the next
  1552. chapter are more convenient for data handling operations, although the
  1553. random files in this chapter have uses of their own, especially when
  1554. working with machine language.
  1555.  
  1556. Random files on the Commodore disk drive reach the individual 256-byte
  1557. blocks of data stored on the disk.  As was mentioned in the first
  1558. chapter, there are a total of 683 blocks on the diskette, of which 664
  1559. are free on a blank diskette.
  1560.  
  1561. The diskette is divided into tracks, which are laid out as concentric
  1562. circles on the surface of the diskette.  There are 35 different tracks,
  1563. starting with track 1 at the outside of the diskette to track 35 at
  1564. the center.  Track 18 is used for the directory, and the DOS fills up
  1565. the diskette from the center outward.
  1566.  
  1567. Each track is subdivided into blocks.  Because there is more room on
  1568. the outer tracks, there are more blocks there.  The outer tracks
  1569. contain 21 blocks each, while the inner ones only have 17 blocks each.
  1570. The table below shows the number of blocks per track.
  1571.  
  1572.  
  1573.        Table 6.1: Track and Block Format
  1574.  +--------------+-------------+-------------+
  1575.  | TRACK NUMBER | BLOCK RANGE | TOTAL BLOCK |
  1576.  +--------------+-------------+-------------+
  1577.  |    1 to 17   |   0 to 20   |      21     |
  1578.  |   18 to 24   |   0 to 18   |      19     |
  1579.  |   25 to 30   |   0 to 17   |      18     |
  1580.  |   31 to 35   |   0 to 16   |      17     |
  1581.  +--------------+-------------+-------------+
  1582.  
  1583. The DOS contains commands for reading and writing directly to any
  1584. track and block on the diskette.  There are also commands for checking
  1585. to see which blocks are available, and for marking off used blocks.
  1586.  
  1587. These commands are transmitted through the command channel (channel
  1588. #15), and tell the disk what to do with the data.  The data must be
  1589. read later through one of the open data channels.
  1590.  
  1591.  
  1592.  
  1593. 6.2 OPENING A DATA CHANNEL FOR RANDOM ACCESS
  1594.  
  1595. When working with random access files, you need to have 2 channels
  1596. open to the disk: one for the commands, and the other for the data.
  1597. The command channel is OPENed to channel 15, just like other disk
  1598. commands you've encountered so far.  The data channel for random
  1599. access files is OPENed by selecting the pound sign (#) as the file
  1600. name.
  1601.  
  1602. FORMAT FOR OPEN STATEMENT FOR RANDOM ACCESS DATA:
  1603.  
  1604.    OPEN file#, device#, channel#, "#"
  1605.  
  1606. or optionally
  1607.  
  1608.    OPEN file#, device#, channel#, "#buffer#"
  1609.  
  1610. EXAMPLES OF OPENING RANDOM ACCESS DATA CHANNEL:
  1611.  
  1612.                          +-------------------------+
  1613.    OPEN 5,8,5,"#" <------+ DON'T CARE WHICH BUFFER |
  1614.              +----------------+--------+
  1615.    OPEN A,B,C,"#2" <-----+ PICK BUFFER #2 |
  1616.               +----------------+
  1617.  
  1618. 6.3 BLOCK-READ
  1619.  
  1620. FORMAT FOR BLOCK-READ COMMAND:
  1621.  
  1622.     PRINT#file#, "BLOCK-READ:" channel; drive; track; block
  1623.  
  1624. or abbreviated as
  1625.  
  1626.     PRINT#file#, "B-R:" channel; drive; track; block
  1627.  
  1628. This command will move one block of data from the diskette into the
  1629. selected channel.  Once this operation has been performed, the INPUT#
  1630. and GET# statements can read the information.
  1631.  
  1632. SAMPLE PROGRAM TO READ BLOCK 2 FROM TRACK 18: (stores contents in B$)
  1633.  
  1634.       +---------+ +-------+  +-------+
  1635.       | CHANNEL | | DRIVE |  | TRACK |
  1636.       +---------+ +-------+  +-------+
  1637.             | |          |
  1638.             | |  +-------+
  1639.  10 OPEN 15,8,15    | |  |           +-------+
  1640.  20 OPEN 5,8,5,"#"  | |  |           | BLOCK |
  1641.  30 PRINT#15,"B-R:" 5;0;18;2 <-------+-------+
  1642.  40 B$=""
  1643.  50 FOR L=0 TO 255                  +----------------+
  1644.  60 GET#5,A$                        | COLLECT ENTIRE |
  1645.  70 IF ST = 0 THEN B$=B$+A$:NEXT L  | BLOCK: BYTE    |
  1646.  80 PRINT "FINISHED"     |          | BY BYTE        |
  1647.  90 CLOSE 5:CLOSE 15     +----------+----------------+
  1648.  
  1649.  
  1650.  
  1651. 6.4 BLOCK-WRITE
  1652.  
  1653. The BLOCK-WRITE command is the exact opposite of the BLOCK-READ
  1654. command.  First you must fill up a data buffer with your information,
  1655. then you write that buffer to the correct location on the disk.
  1656.  
  1657. FORMAT FOR BLOCK-WRITE COMMAND:
  1658.  
  1659.    PRINT#file#, "BLOCK-WRITE:" channel; drive; track; block
  1660.  
  1661. or abbreviated as
  1662.  
  1663.    PRINT#file, "B-W:" channel; drive; track; block
  1664.  
  1665. When the data is being put into the buffer, a pointer in the DOS keeps
  1666. track of how many characters there are.  When you perform the BLOCK-
  1667. WRITE operation, that pointer is recorded on the disk.  That is the
  1668. reason for the ST check in line 70 of the program above: the ST will
  1669. become non-zero when you try to read past the end-of-file marker
  1670. within the record.
  1671.  
  1672. SAMPLE PROGRAM TO WRITE DATA ON TRACK 1, SECTOR 1:
  1673.  
  1674.  10 OPEN 15,8,15
  1675.  20 OPEN 5,8,5,"#":REM OPEN A RANDOM ACCESS CHANNEL
  1676.  30 FOR L=1 TO 50
  1677.  40 PRINT#5,"TEST"
  1678.  50 NEXT
  1679.  60 PRINT#15,"B-W:"5;0;1;1
  1680.  70 CLOSE 5:CLOSE 15
  1681.  
  1682.  
  1683.  
  1684. 6.5 BLOCK-ALLOCATE
  1685.  
  1686. In order to safely use random files along with regular files, your
  1687. programs must check the BAM to find available blocks, and change the
  1688. BAM to reflect that you've used them.  Once you update the BAM, your
  1689. random files will be safe -- at least unless you perform the VALIDATE
  1690. command (see chapter 3).
  1691.  
  1692. FORMAT FOR THE BLOCK-ALLOCATE COMMAND:
  1693.  
  1694.    PRINT#file#, "BLOCK-ALLOCATE:" drive; track; block
  1695.  
  1696. How do you know which blocks are available to use?  If you try a block
  1697. that isn't available the DOS will set the error message to number 65,
  1698. NO BLOCK, and set the track and block numbers to the next available
  1699. track and block number.  Therefore, any time you attempt to write a
  1700. block to the disk, you must first try to allocate that block. If that
  1701. block isn't available, read the next block available from the error
  1702. channel and then allocate that block.
  1703.  
  1704. EXAMPLE OF PROCEDURE TO ALLOCATE BLOCK:
  1705.  
  1706.                 +-------+
  1707.                 | DRIVE |
  1708.  10 OPEN 15,8,15   +--------+-------+
  1709.  20 OPEN 5,8,5,"#" |        | TRACK |
  1710.  30 PRINT#5,"DATA" | +------+-------+
  1711.  40 T=1:B=1        | |      | BLOCK |
  1712.  50 PRINT#15,"B-A:"0;T;B <--+-------+
  1713.  60 INPUT#15,A,B$,C,D
  1714.  70 IF A=65 THEN T=C:B=D:GOTO 50
  1715.  80 PRINT#15,"B-W:"5;0;1;1
  1716.  90 CLOSE 5:CLOSE 15
  1717.  
  1718.  
  1719.  
  1720. 6.6 BLOCK-FREE
  1721.  
  1722. The BLOCK-FREE command is the opposite of BLOCK-ALLOCATE, in that it
  1723. frees a block that you don't want to use anymore for use by the system.
  1724. It is vaguely similar to the SCRATCH command for files, since it
  1725. doesn't really erase any data from the disk -- just frees the entry,
  1726. in this case just in the BAM.
  1727.  
  1728. FORMAT FOR BLOCK-FREE COMMAND:
  1729.  
  1730.    PRINT#file#, "BLOCK-FREE:" drive; track; block
  1731.  
  1732. or abbreviated as
  1733.  
  1734.    PRINT#file#, "B-F:" drive; track; block
  1735.  
  1736.  
  1737.  
  1738. 6.7 USING RANDOM FILES
  1739.  
  1740. The only problem with what you've learned about random files so far is
  1741. that you have no way of keeping track of which blocks on the disk you
  1742. used.  After all, you can't tell one used block on the BAM from
  1743. another.  You can't tell whether it contains your random file, just
  1744. part of a program, or even sequential or relative files.
  1745.  
  1746. To keep track, the most common method is to build up a sequential file
  1747. to go with each random file.  Use this file to keep just a list of
  1748. record, track, and block locations. This means that there are 3
  1749. channels open to the disk for each random file: one for the command
  1750. channel, one for the random data, and the other for the sequential
  1751. data. This also means that there are 2 buffers that you're filling up
  1752. at the same time!
  1753.  
  1754. SAMPLE PROGRAM WRITING 10 RANDOM-ACCESS BLOCKS WITH SEQUENTIAL FILE:
  1755.  
  1756.  10 OPEN 15,8,15
  1757.  20 OPEN 5,8,5,"#"
  1758.  30 OPEN 4,8,4,"@0:KEYS,S,W"
  1759.  40 A$="RECORD CONTENTS #"
  1760.  50 FOR R=1 TO 10
  1761.  70 PRINT#5,A$","R
  1762.  90 T=1:B=1  <-------------------------+---------------------+
  1763.  100 PRINT#15,"B-A:"0;T;B  <-----------+ FIND NEXT AVAILABLE |
  1764.  110 INPUT#15,A,B$,C,D  <--------------+ TRACK & BLOCK       |
  1765.  120 IF A=65 THEN T=C:B=D:GOTO 100  <--+---------------------+
  1766.  130 PRINT#15,"B-W:"5;0;T;B
  1767.  140 PRINT#4,T","B
  1768.  150 NEXT R
  1769.  160 CLOSE 4:CLOSE 5:CLOSE 15
  1770.  
  1771. SAMPLE PROGRAM READING BACK 10 RANDOM-ACCESS BLOCKS WITH SEQUENTIAL
  1772. FILE:
  1773.  
  1774.  10 OPEN 15,8,15                  +------------+
  1775.  20 OPEN 5,8,5,"#"                | CHECKS TO  |
  1776.  30 OPEN 4,8,4,"KEYS,S,R"         | MAKE SURE  |
  1777.  40 FOR R=1 TO 10                 | DATA IS OK |
  1778.  50 INPUT#4,T,B                   +------------+
  1779.  60 PRINT#15,"B-R:"5;0;T;B        |
  1780.  80 INPUT#5,A$,X                  |
  1781.  90 IF A$<>"RECORD CONTENTS #" OR X<>R THEN STOP
  1782.  100 PRINT A$;R
  1783.  110 PRINT#15,"B-F:"0;T;B  <---+---------------+
  1784.  120 NEXT R                    | FREES THIS    |
  1785.  130 CLOSE 4:CLOSE 5           | TRACK & BLOCK |
  1786.  140 PRINT#15,"S0:KEYS"        | FOR LATER USE |
  1787.  150 CLOSE 15                  +---------------+
  1788.  
  1789.  
  1790.  
  1791. 6.8 BUFFER-POINTER
  1792.  
  1793. The buffer pointer keeps track of where the last piece of data was
  1794. written.  It also is the pointer for where the next piece of data is
  1795. to be read.  By changing the buffer pointer's location within the
  1796. buffer, you can get random access to the individual bytes within a
  1797. block.  This way, you can subdivide each block into records.
  1798.  
  1799. For example, let's take a hypothetical mailing list.  The information
  1800. such as name, address, etc., will take up a total of 64 characters
  1801. maximum.  We could divide each block of the random access file into 4
  1802. separate records, and by knowing the track, sector, and record numbers,
  1803. we can access that individual record.
  1804.  
  1805. FORMAT FOR BUFFER-POINTER COMMAND:
  1806.  
  1807.    PRINT#file#, "BUFFER-POINTER:" channel; location
  1808.  
  1809. or abbreviated as
  1810.  
  1811.    PRINT#file#, "B-P:" channel; location
  1812.  
  1813. EXAMPLE OF SETTING POINTER TO 64TH CHARACTER OF BUFFER:
  1814.  
  1815.    PRINT#15, "B-P:" 5; 64
  1816.  
  1817. Here are versions of the random access writing and reading programs
  1818. shown above, modified to work with records within blocks:
  1819.  
  1820. SAMPLE PROGRAM WRITING 10 RANDOM-ACCESS BLOCKS WITH 4 RECORDS EACH:
  1821.  
  1822.  10 OPEN 15,8,15
  1823.  20 OPEN 5,8,5,"#"
  1824.  30 OPEN 4,8,4,"@0:KEYS,S,W"
  1825.  40 A$="RECORD CONTENTS #"             +--------------------+
  1826.  50 FOR R=1 TO 10                      | SET POSITION       |
  1827.  60 FOR L=1 TO 4                       | TO 1, 65, 129, 193 |
  1828.  70 PRINT#15,"B-P:"5;(L-1)*64+1  <-----+--------------------+
  1829.  80 PRINT#5,A$","L
  1830.  90 NEXT L
  1831.  100 T=1:B=1                           +---------------------+
  1832.  110 PRINT#15,"B-A:"0;T;B  <-----------+ FIND NEXT AVAILABLE |
  1833.  120 INPUT#15,A,B$,C,D  <--------------+ TRACK & BLOCK       |
  1834.  130 IF A=65 THEN T=C:B=D:GOTO 110  <--+---------------------+
  1835.  140 PRINT#15,"B-W:"5;0;T;B
  1836.  150 PRINT#4,T","B
  1837.  160 NEXT R
  1838.  170 CLOSE 4:CLOSE 5:CLOSE 15
  1839.  
  1840. SAMPLE PROGRAM READING BACK 10 RANDOM-ACCESS BLOCKS WITH 4 RECORDS
  1841. EACH:
  1842.  
  1843.  10 OPEN 15,8,15
  1844.  20 OPEN 5,8,5,"#"
  1845.  30 OPEN 4,8,4,"KEYS,S,R"
  1846.  40 FOR R=1 TO 10
  1847.  50 INPUT#4,T,B
  1848.  60 PRINT#15,"B-R:"5;0;T;B
  1849.  70 FOR L=1 TO 4
  1850.  80 PRINT#15,"B-P:"5;(L-1)*64+1
  1851.  85 INPUT#5,A$,X
  1852.  90 IF A$<>"RECORD CONTENTS #" OR X<>L THEN STOP
  1853.  95 PRINT R;A$;L
  1854.  100 NEXT L
  1855.  110 PRINT#15,"B-F:"0;T;B
  1856.  120 NEXT R
  1857.  130 CLOSE 4:CLOSE 5
  1858.  140 PRINT#15,"S0:KEYS"
  1859.  150 CLOSE 15
  1860.  
  1861.  
  1862.  
  1863. 6.9 USER1 and USER2
  1864.  
  1865. The USER commands are generally designed to work with machine language
  1866. (see chapter 8 for more on this).  The USER1 and USER2 commands are
  1867. special versions of the BLOCK-READ and BLOCK-WRITE commands, but...
  1868. with an important difference: the way USER1 and USER2 work with the
  1869. buffer-pointer.
  1870.  
  1871. The BLOCK-READ command reads up to 256 characters, but stops reading
  1872. when the buffer-pointer stored with the block says that block is
  1873. finished.  The USER1 command performs the BLOCK-READ operation, but
  1874. first forces the pointer to 255 in order to read the entire block of
  1875. data from the disk.
  1876.  
  1877. FORMAT FOR USER1 COMMAND
  1878.  
  1879.    PRINT#file#, "U1:" channel; drive; track; block
  1880.  
  1881. or
  1882.  
  1883.    PRINT#file#, "UA:" channel; drive; track; block
  1884.  
  1885. There is no difference between the U1 and UA designations for this
  1886. command.
  1887.  
  1888. The BLOCK-WRITE command writes the contents of the buffer to the block
  1889. on the disk along with the value of the buffer-pointer.  The USER2
  1890. command writes the buffer without disturbing the buffer-pointer value
  1891. already stored on that block of the diskette.  This is useful when a
  1892. block is to be read in with BLOCK-READ, updated through the BUFFER-
  1893. POINTER and PRINT# statements, and then written back to the diskette
  1894. with USER2.
  1895.  
  1896. FORMAT FOR USER2 COMMAND:
  1897.  
  1898.    PRINT#file#, "U2:" channel; drive; track; block
  1899.  
  1900. or
  1901.  
  1902.    PRINT#file#, "UB:" channel; drive; track; block
  1903.  
  1904. For a more complex sample program, see Appendix C.
  1905.  
  1906.  
  1907.  
  1908. 7. RELATIVE FILES
  1909.  
  1910. [ 7.1 INTRODUCTION ]
  1911.  
  1912. RELative files allow you to easily zero in on exactly the piece of
  1913. data that you want from the file.  It is more convenient for data
  1914. handling because it allows you to structure your files into records,
  1915. and into fields within those records.
  1916.  
  1917. The DOS keeps track of the tracks and blocks used, and even allows
  1918. records to overlap from one block to the next.  It is able to do this
  1919. because it establishes side sectors, a series of pointers for the
  1920. beginning of each record.  Each side sector can point to up to 120
  1921. records, and there may be 6 side sectors in a file.  There can be up
  1922. to 720 records in a file, and each record can be up to 254 characters,
  1923. so the file could be as large as the entire diskette.
  1924.  
  1925.  
  1926.  
  1927. 7.2 CREATING A RELATIVE FILE
  1928.  
  1929. When a RELative file is first to be used, the OPEN statement will
  1930. create that file; after that, that same file will be used.  The
  1931. replace option (with the @ sign) does not erase and re-create the file.
  1932. . The file can be expanded, read, and written into.
  1933.  
  1934. FORMAT FOR THE OPEN STATEMENT TO CREATE RELATIVE FILE:
  1935.  
  1936.     OPEN file#, device#, channel#, "name,L," + CHR$(record length)
  1937.  
  1938. EXAMPLES OF OPEN STATEMENT CREATING RELATIVE FILES:
  1939.  
  1940.     OPEN 2, 8, 2, "FILE,L," + CHR$(100)  <--+---------------+
  1941.     OPEN F, 8, F, A$+ ",L," + CHR$(Q)  <----+ Record Length |
  1942.     OPEN A, B, C, "TEST,L," + CHR$(33)  <---+---------------+
  1943.  
  1944. Table 7.1: RELATIVE FILE FORMAT
  1945.  
  1946.  +---------------------------------------------------------------+
  1947.  | DATA BLOCK                                                    |
  1948.  +---------------------------------------------------------------+
  1949.  | BYTE   | DEFINITION                                           |
  1950.  +--------+------------------------------------------------------+
  1951.  | 0,1    | Track and block of next data block.                  |
  1952.  +--------+------------------------------------------------------+
  1953.  | 2-256  | 254 bytes of data. Empty records contain FF (all     |
  1954.  |        | binary ones) in the first byte followed by 00        |
  1955.  |        | (binary all zeros) to the end of the record.         |
  1956.  |        | Partially filled records are padded with nulls (00). |
  1957.  +---------------------------------------------------------------+
  1958.  | SIDE SECTOR BLOCK                                             |
  1959.  +--------+------------------------------------------------------+
  1960.  | BYTE   | DEFINITION                                           |
  1961.  +--------+------------------------------------------------------+
  1962.  | 0,1    | Track and block of next side sector block.           |
  1963.  +--------+------------------------------------------------------+
  1964.  | 2      | Side sector number. (0-5)                            |
  1965.  +--------+------------------------------------------------------+
  1966.  | 3      | Record length.                                       |
  1967.  +--------+------------------------------------------------------+
  1968.  | 4,5    | Track and block of first side sector (number 0)      |
  1969.  +--------+------------------------------------------------------+
  1970.  | 6,7    | Track and block of second side sector (number 1)     |
  1971.  +--------+------------------------------------------------------+
  1972.  | 8,9    | Track and block of third side sector (number 2)      |
  1973.  +--------+------------------------------------------------------+
  1974.  | 10,11  | Track and block of fourth side sector (number 3)     |
  1975.  +--------+------------------------------------------------------+
  1976.  | 12,13  | Track and block of fifth side sector (number 4)      |
  1977.  +--------+------------------------------------------------------+
  1978.  | 14,15  | Track and block of sixth side sector (number 5)      |
  1979.  +--------+------------------------------------------------------+
  1980.  | 16-256 | Track and block pointers to 120 data blocks.         |
  1981.  +--------+------------------------------------------------------+
  1982.  
  1983. Upon execution, the DOS first checks to see if the file exists.  If it
  1984. does, then nothing happens.  The only way to erase an old relative
  1985. file is by using the SCRATCH command (see chapter 4), but not by using
  1986. the replace option.
  1987.  
  1988.  
  1989.  
  1990. 7.3 USING RELATIVE FILES
  1991.  
  1992. In order to OPEN a relative file once it exists, the format is simpler.
  1993.  
  1994.  
  1995. FORMAT FOR OPENING AN EXISTING RELATIVE FILE:
  1996.  
  1997.     OPEN file#, device#, channel#, "name"
  1998.  
  1999. In this case, the DOS automatically knows that it is a relative file.
  2000. This syntax, and the one shown in the above section, both allow either
  2001. reading or writing to the file.
  2002.  
  2003. In order to read or write, you must, before any operation, position
  2004. the file pointer to the correct record position.
  2005.  
  2006. FORMAT FOR POSITION COMMAND:
  2007.  
  2008.     PRINT#file#, "P" CHR$(channel#+96) CHR$(rec#lo) CHR$(rec#hi)
  2009.     CHR$(position)
  2010.  
  2011. EXAMPLES OF POSITION COMMAND:
  2012.  
  2013.     PRINT#15, "P" CHR$(2+96) CHR$(1) CHR$(0)
  2014.  
  2015.     PRINT#15, "P" CHR$(CH+96) CHR$(R1) CHR$(R2)
  2016.  
  2017.     PRINT#15, "P" CHR$(4+96) CHR$(R1) CHR$(R2) CHR$(P)
  2018.                        |          |        |        |
  2019.        +-----------+----------+--------+  +-----+---------+
  2020.        | Channel # | Record #          |  | Position      |
  2021.        +-----------+-------------------+  | within Record |
  2022.                           +---------------+
  2023.  
  2024. The 2-byte format for the record number is needed because one byte can
  2025. only hold 256 different numbers, and we can have over 700 records in
  2026. the file.  The rec# lo contains the least significant part of the
  2027. address, and the rec# hi is the most significant part.  This could be
  2028. translated to the actual record number by the formula REC# = REC HI *
  2029. 256 + REC LO.
  2030.  
  2031. If the record number is known, the high and low bytes can be
  2032. determined as follows:
  2033.  
  2034.     REC# HI= INT(REC#/256)
  2035.     REC# LO= REC# - REC# HI*256
  2036.  
  2037. EXAMPLE:
  2038.  
  2039.     PRINT#15, "P" CHR$(4+96) CHR$(R1) CHR$(R2) CHR$(0)
  2040.  
  2041.     IF REC# = 540: R2 = INT(540/256) ... so R2 = 2
  2042.                    RI = 540 - R2*256 ... so RI = 28
  2043.  
  2044. Let's assume we have a mailing list.  The list consists of 8 pieces of
  2045. data, according to this chart:
  2046.  
  2047.     Field Name               Length
  2048.  
  2049.     first name               12
  2050.     last name                15
  2051.     address line 1           20
  2052.     address line 2           20
  2053.     city                     12
  2054.     state                     2
  2055.     zip code                  9
  2056.     phone number             10
  2057.     ----------------------------
  2058.     TOTAL                   100
  2059.  
  2060. This is how the record length is determined.  We would probably want
  2061. to allow an extra character in length for each field, to allow for
  2062. separations; otherwise the INPUT# command would pick up a much longer
  2063. piece of the file than needed, just like in sequential files.
  2064. Therefore, we'll set up a file with a length of 108 characters per
  2065. record. In the first record, we'll put the number 1, representing the
  2066. largest record# used so far. Here is the program as described so far:
  2067.  
  2068.  5 X=0
  2069.  10 OPEN 1,8,15
  2070.  20 OPEN 2,8,3,"0:MAILING LIST,L," + CHR$(108)
  2071.  30 GOSUB 900
  2072.  40 PRINT#1 "P" CHR$(3+96) CHR$(1) CHR$(0) CHR$(1)
  2073.  50 GOSUB 900
  2074.  60 IF E=50 THEN PRINT#2,1:GOTO 40
  2075.  70 INPUT#2,X
  2076.  75 PRINT X
  2077.  300 STOP:CLOSE 1:CLOSE 2:END
  2078.  900 INPUT#1,E,B$,C,D: REM ERROR SUBROUTINE
  2079.  910 IF (E=50) OR (E<20) THEN RETURN
  2080.  920 PRINT E;B$;C;D:STOP:RETURN
  2081.  
  2082. Error #50 which is checked in line 60 of the program is the RECORD NOT
  2083. PRESENT error, which means that the record hadn't been created yet.
  2084. Writing into the record will solve the problem.  This error condition
  2085. must be watched carefully within your programs.
  2086.  
  2087. So far, all it does is create the file and the first record, but
  2088. doesn't actually put any data in it.  Below is a greatly expanded
  2089. version of the program, to actually allow you to work with a mailing
  2090. list where the records are coded by numbers.
  2091.  
  2092. start tok64 maillist.prg
  2093.  5 a(1)=12: a(2)=15: a(3)=20: a(4)=20: a(5)=12: a(6)=2: a(7)=9: \
  2094.    a(8)=10
  2095.  9 rem open relative file called "mailing list"
  2096.  10 open 1,8,15:open 2,8,3,"0:mailing list,l,"+chr$(108):gosub 900
  2097.  20 print#1,"p" chr$(3+96) chr$(1) chr$(0) chr$(1):input#2,x$:\
  2098.     x=val(x$): if x=0 then x=2
  2099.  30 input "read,write,or end";j$:if j$="e" then close 2:close 1:end
  2100.  40 if j$="w" then 200
  2101.  50 print:input "record #";r:if r<0 or r>x then 50:rem read rout
  2102.  60 if r<2 then 30
  2103.  70 r1=r:r2=0:if r1>256 then r2=int(r1/256):r1=r1-256*r2
  2104.  80 restore:data 1,first name,14,last name,30,address1,51,address2
  2105.  90 data 72,city,85,state,88,zip,98,phone#
  2106.  100 for l=1 to 8:read a,a$:print#1,"p" chr$(3+96) chr$(r1) \
  2107.      chr$(r2) chr$(a):gosub 900
  2108.  110 on a/50 goto 50
  2109.  115 input#2,z$:print a$,z$:next:goto 50
  2110.  200 print:input "record #";r:if r<0 or r>500 then 200:rem write rout
  2111.  210 if r<2 then 30
  2112.  215 if r>x then r=x+1:print:print "record#"; r
  2113.  220 r1=r:r2=0:if r>255 then r2=int(r1/256):r1=r1-256*r2
  2114.  230 restore:for l=1 to 8:read a,a$:print#1,"p" chr$(3+96)chr$(r1) \
  2115.      chr$(r2) chr$(a)
  2116.  232 gosub 900
  2117.  235 print a$;:input z$:if len(z$)>a(l) then z$=left$(z$,a(l))
  2118.  240 print#2,z$:gosub 900:next:if r>x then x=r
  2119.  245 print#1,"p" chr$(3+96) chr$(1) chr$(0) chr$(1)
  2120.  250 print#2,x:gosub 900:goto 200
  2121.  900 input#1,a,b$,c,d:if a<20 then return:rem error check rout
  2122.  910 if a<>50 then print a;b$,c;d:stop:return
  2123.  920 if j$="r" then print b$
  2124.  930 return
  2125. stop tok64
  2126.  
  2127. begin 644 MAILLIST.PRG
  2128. M`0A)"`4`02@Q*;(Q,CH@02@R*;(Q-3H@02@S*;(R,#H@02@T*;(R,#H@02@U
  2129. M*;(Q,CH@02@V*;(R.B!!*#<ILCDZ02@X*;(Q,`!X"`D`CR!/4$5.(%)%3$%4
  2130. M259%($9)3$4@0T%,3$5$(")-04E,24Y'($Q)4U0B`*X("@"?(#$L."PQ-3J?
  2131. M(#(L."PS+"(P.DU!24Q)3D<@3$E35"Q,+"*JQR@Q,#@I.HT@.3`P`.L(%`"8
  2132. M,2PB4"(@QR@SJCDV*2#'*#$I(,<H,"D@QR@Q*3J$,BQ8)#I8LL4H6"0I.B"+
  2133. M(%BR,""G(%BR,@`="1X`A2`B4D5!1"Q74DE412Q/4B!%3D0B.THD.HL@2B2R
  2134. M(D4B(*<@H"`R.J`@,3J``#`)*`"+($HDLB)7(B"G(#(P,`!B"3(`F3J%(")2
  2135. M14-/4D0@(R([4CJ+(%*S,""P(%*Q6""G(#4P.H\@4D5!1"!23U54`'$)/`"+
  2136. M(%*S,B"G(#,P`*0)1@!2,;)2.E(RLC`ZBR!2,;$R-38@IR!2,K*U*%(QK3(U
  2137. M-BDZ4C&R4C&K,C4VK%(R`-X)4`",.H,@,2Q&25)35"!.04U%+#$T+$Q!4U0@
  2138. M3D%-12PS,"Q!1$1215-3,2PU,2Q!1$1215-3,@`&"EH`@R`W,BQ#2519+#@U
  2139. M+%-4051%+#@X+%I)4"PY."Q02$].12,`0`ID`($@3+(Q(*0@.#J'($$L020Z
  2140. MF#$L(E`B(,<H,ZHY-BD@QRA2,2D@QRA2,BG'*$$I.HT@.3`P`%`*;@"1($&M
  2141. M-3`@B2`U,`!I"G,`A#(L6B0ZF2!!)"Q:)#J".HD@-3``GPK(`)DZA2`B4D5#
  2142. M3U)$(",B.U(ZBR!2LS`@L"!2L34P,""G(#(P,#J/(%=2251%(%)/550`K@K2
  2143. M`(L@4K,R(*<@,S``T0K7`(L@4K%8(*<@4K)8JC$ZF3J9(")214-/4D0C(CL@
  2144. M4@`#"]P`4C&R4CI2,K(P.HL@4K$R-34@IR!2,K*U*%(QK3(U-BDZ4C&R4C&K
  2145. M,C4VK%(R`#D+Y@",.H$@3+(Q(*0@.#J'($$L020ZF#$L(E`B(,<H,ZHY-BG'
  2146. M*%(Q*2#'*%(R*2#'*$$I`$,+Z`"-(#DP,`!O"^L`F2!!)#LZA2!:)#J+(,,H
  2147. M6B0IL4$H3"D@IR!:)++(*%HD+$$H3"DI`(T+\`"8,BQ:)#J-(#DP,#J".HL@
  2148. M4K%8(*<@6+)2`*\+]0"8,2PB4"(@QR@SJCDV*2#'*#$I(,<H,"D@QR@Q*0#$
  2149. M"_H`F#(L6#J-(#DP,#J)(#(P,`#R"X0#A#$L02Q")"Q#+$0ZBR!!LS(P(*<@
  2150. MCCJ/($524D]2($-(14-+(%)/550`#PR.`XL@0;.Q-3`@IR"9($$[0B0L0SM$
  2151. A.I`ZC@`C#)@#BR!*)+(B4B(@IR"9($(D`"D,H@..````
  2152. `
  2153. end
  2154.  
  2155. This program asks for record numbers when retrieving records.  It
  2156. won't let you retrieve from beyond the end of the file, and if you try
  2157. to write beyond the end it forces you to write on the next higher
  2158. record.
  2159.  
  2160. A more advanced version than this would keep track of the items by
  2161. "keys", to index the records.  For example, you would probably want to
  2162. search for a record by name, or print out labels by zip code.  For
  2163. this you would need a separate list of keys and record numbers,
  2164. probably stored in sequential files.
  2165.  
  2166. When working with a new relative file that will soon be very large, it
  2167. will save much time to create a record at the projected end of the
  2168. file. In other words, if you expect the file to be 1000 records long,
  2169. create a record# 1000 as soon as the file is created. This will force
  2170. the DOS to create all intermediate records, making later use of those
  2171. records much faster.
  2172.  
  2173. EXAMPLE OF CREATING LARGE FILE:
  2174.  
  2175.     OPEN 1, 8, 15: OPEN 2, 8, 2, "0:REL,L," + CHR$(60)
  2176.     PRINT#1, "P" CHR$(2+96) CHR$(0) CHR$(4) CHR$(1)
  2177.     PRINT#2, "END"
  2178.     CLOSE 2: CLOSE 1
  2179.  
  2180. PROGRAM AND EXPLANATION
  2181.  
  2182. start tok64 relfile.prg
  2183.  1 rem relative file program
  2184.  2 dim a$(5):dim c$(5):print"{clear}"
  2185.  3 print "hit f1 to construct a relative file"
  2186.  4 print "hit f3 to read a relative file"
  2187.  5 print "hit f5 to read the error channel":gosub 5000
  2188.  6 input "enter relative file name";z$
  2189.  8 open 2,8,2,z$+",l,"+chr$(50):rem create the relative file
  2190.  9 open 1,8,15
  2191.  11 gosub 1000
  2192.  20 for i=1 to 5
  2193.  30 print#1,"p" chr$(2+96)chr$(i)chr$(0)chr$(1):rem position the \
  2194.     record pointer
  2195.  40 print "enter a name"
  2196.  50 input a$(i)
  2197.  60 print#2,a$(i)
  2198.  63 input "enter additional info";c$(i)
  2199.  65 print#1,"p" chr$(2+96)chr$(i)chr$(0)chr$(25):rem position \
  2200.     pointer to 25th character
  2201.  67 print#2,c$(i)
  2202.  70 next i
  2203.  75 print "do you wish to replace a record":input d$
  2204.  76 if d$="n" then 80
  2205.  77 gosub 8000
  2206.  78 go to 75
  2207.  80 print "the relative file is constructed"
  2208.  82 for de=1 to 2500: next de: gosub 6000
  2209.  85 close 2
  2210.  90 end:stop
  2211.  100 input "enter desired file to read";z$
  2212.  105 open 2,8,2,z$:open 1,8,15
  2213.  106 print "reading " z$
  2214.  110 for i=1 to 5
  2215.  115 rem for i=5 to 1 step -1
  2216.  130 print#1,"p" chr$(2+96)chr$(i)chr$(0)chr$(1)
  2217.  160 input#2,a$(i)
  2218.  170 print "record#(" i ")=", a$(i)
  2219.  175 k=6-i
  2220.  177 print#1,"p" chr$(2+96)chr$(i)chr$(0)chr$(25)
  2221.  179 input#2,c$(i):print "additional info:";c$(i)
  2222.  180 next i
  2223.  181 print "do you wish to replace a record":input d$
  2224.  182 if d$="n" then 185
  2225.  183 gosub 8000
  2226.  184 go to 181
  2227.  185 gosub 1000
  2228.  186 j=i+1
  2229.  190 print "end of read":for de=1 to 1500:next de:gosub 6000:\
  2230.      close 2:close 1:end
  2231.  1000 input#1,a,b$,c,d:if a<20 then return
  2232.  1001 if a<>50 then print a,b$,c,d :stop: return
  2233.  1999 end
  2234.  2000 open 15,8,15
  2235.  2001 input#15,a,b$,c,d
  2236.  2002 print a,b$,c,d
  2237.  2003 close 15:end
  2238.  5000 get s$:if s$="" then 5000: rem scan keyboard for function \
  2239.       key chr$ codes
  2240.  5001 if s$=chr$(133) then 6: rem assign f1 function key
  2241.  5002 if s$=chr$(134) then 100: rem assign f3 function key
  2242.  5003 if s$=chr$(135) then 2000: rem assign f5 function key
  2243.  5004 return
  2244.  6000 print "{clear}hit f7: for hard copy or c to continue"
  2245.  6001 get p$: if p$<>chr$(136) and p$="c" then return
  2246.  6002 for de=1 to 500: next de: if p$ ="" or p$<>chr$(136) then 6000
  2247.  6003 open 4,4:cmd 4
  2248.  6004 print#4,"the " z$ " file consists of:"
  2249.  6005 for i=1 to 5
  2250.  6010 print#4,"record #";i;"=";a$(i)
  2251.  6012 print#4,"additional info ";i;"=";c$(i)
  2252.  6015 next i
  2253.  6020 close 4:return
  2254.  7000 rem to read in records in reverse order remove the rem in \
  2255.       line #115 and
  2256.  7002 rem put a rem before line#110
  2257.  7005 rem to read the 1st field of the 1st record and the 2nd \
  2258.       field of the last
  2259.  7007 rem replace the chr$(i) in line 177 with chr$(k)
  2260.  8000 print "which record # do you want replaced":input i
  2261.  8001 input "enter new record";a$(i)
  2262.  8002 print#1,"p" chr$(2+96)chr$(i)chr$(0)chr$(1):rem position \
  2263.       file pointer
  2264.  8003 print#2,a$(i)
  2265.  8004 input "enter new record (field 2)";c$(i)
  2266.  8005 print#1,"p" chr$(2+96)chr$(i)chr$(0)chr$(25):rem position \
  2267.       file pointer
  2268.  8007 print#2,c$(i)
  2269.  8009 print "record#";i;" has been replaced"
  2270.  8010 return
  2271. stop tok64
  2272.  
  2273. begin 644 RELFILE.PRG
  2274. M`0@="`$`CR!214Q!5$E612!&24Q%(%!23T=204T`-@@"`(8@020H-2DZAB!#
  2275. M)"@U*3J9(I,B`&((`P"9(")(250@1C$@5$\@0T].4U1254-4($$@4D5,051)
  2276. M5D4@1DE,12(`B0@$`)D@(DA)5"!&,R!43R!214%$($$@4D5,051)5D4@1DE,
  2277. M12(`N0@%`)D@(DA)5"!&-2!43R!214%$(%1(12!%4E)/4B!#2$%.3D5,(CJ-
  2278. M(#4P,#``W0@&`(4@(D5.5$52(%)%3$%4259%($9)3$4@3D%-12([6B0`$PD(
  2279. M`)\@,BPX+#(L6B2J(BQ,+"*JQR@U,"DZCR!#4D5!5$4@5$A%(%)%3$%4259%
  2280. M($9)3$4`(`D)`)\@,2PX+#$U`"L)"P"-(#$P,#``.0D4`($@2;(Q(*0@-0!V
  2281. M"1X`F#$L(E`B(,<H,JHY-BG'*$DIQR@P*<<H,2DZCR!03U-)5$E/3B!42$4@
  2282. M4D5#3U)$(%!/24Y415(`BPDH`)D@(D5.5$52($$@3D%-12(`EPDR`(4@020H
  2283. M22D`I`D\`)@R+$$D*$DI`,@)/P"%(")%3E1%4B!!1$1)5$E/3D%,($E.1D\B
  2284. M.T,D*$DI``T*00"8,2PB4"(@QR@RJCDV*<<H22G'*#`IQR@R-2DZCR!03U-)
  2285. M5$E/3B!03TE.5$52(%1/(#(U5$@@0TA!4D%#5$52`!H*0P"8,BQ#)"A)*0`B
  2286. M"D8`@B!)`$\*2P"9(")$3R!93U4@5TE32"!43R!215!,04-%($$@4D5#3U)$
  2287. M(CJ%($0D`&$*3`"+($0DLB).(B"G(#@P`&P*30"-(#@P,#``=PI.`,L@I"`W
  2288. M-0"@"E``F2`B5$A%(%)%3$%4259%($9)3$4@25,@0T].4U1254-4140B`,`*
  2289. M4@"!($1%LC$@I"`R-3`P.B""($1%.B"-(#8P,#``R`I5`*`@,@#0"EH`@#J0
  2290. M`/8*9`"%(")%3E1%4B!$15-)4D5$($9)3$4@5$\@4D5!1"([6B0`#@MI`)\@
  2291. M,BPX+#(L6B0ZGR`Q+#@L,34`(@MJ`)D@(E)%041)3D<@(B!:)``P"VX`@2!)
  2292. MLC$@I"`U`$L+<P"/($9/4B!)/34@5$\@,2!35$50("TQ`&H+@@"8,2PB4"(@
  2293. MQR@RJCDV*<<H22G'*#`IQR@Q*0!W"Z``A#(L020H22D`E@NJ`)D@(E)%0T]2
  2294. M1",H(B!)("(I/2(L($$D*$DI`*`+KP!+LC:K20#`"[$`F#$L(E`B(,<H,JHY
  2295. M-BG'*$DIQR@P*<<H,C4I`.@+LP"$,BQ#)"A)*3J9(")!1$1)5$E/3D%,($E.
  2296. M1D\Z(CM#)"A)*0#P"[0`@B!)`!T,M0"9(")$3R!93U4@5TE32"!43R!215!,
  2297. M04-%($$@4D5#3U)$(CJ%($0D`#`,M@"+($0DLB).(B"G(#$X-0`[#+<`C2`X
  2298. M,#`P`$<,N`#+(*0@,3@Q`%(,N0"-(#$P,#``7`RZ`$JR2:HQ`)0,O@"9(")%
  2299. M3D0@3T8@4D5!1"(Z@2!$1;(Q(*0@,34P,#J"($1%.HT@-C`P,#J@(#(ZH"`Q
  2300. M.H``KPSH`X0Q+$$L0B0L0RQ$.HL@0;,R,""G((X`S@SI`XL@0;.Q-3`@IR"9
  2301. M($$L0B0L0RQ$(#J0.B".`-0,SP>``.(,T`>?(#$U+#@L,34`\PS1!X0Q-2Q!
  2302. M+$(D+$,L1``"#=('F2!!+$(D+$,L1``-#=,'H"`Q-3J``%(-B!.A(%,D.HL@
  2303. M4R2R(B(@IR`U,#`P.B"/(%-#04X@2T590D]!4D0@1D]2($953D-424].($M%
  2304. M62!#2%(D($-/1$53`(`-B1.+(%,DLL<H,3,S*2"G(#8Z((\@05-324=.($8Q
  2305. M($953D-424].($M%60"P#8H3BR!3)++'*#$S-"D@IR`Q,#`Z((\@05-324=.
  2306. M($8S($953D-424].($M%60#A#8L3BR!3)++'*#$S-2D@IR`R,#`P.B"/($%3
  2307. M4TE'3B!&-2!&54Y#5$E/3B!+15D`YPV,$XX`%PYP%YD@(I-(250@1C<Z($9/
  2308. M4B!(05)$($-/4%D@3U(@0R!43R!#3TY424Y512(`.PYQ%Z$@4"0Z((L@4"2S
  2309. ML<<H,3,V*2"O(%`DLB)#(B"G((X`<`YR%X$@1$6R,2"D(#4P,#H@@B!$13H@
  2310. MBR!0)""R(B(@L"!0)+.QQR@Q,S8I(*<@-C`P,`!^#G,7GR`T+#0ZG2`T`*0.
  2311. M=!>8-"PB5$A%("(@6B0@(B!&24Q%($-/3E-)4U13($]&.B(`L@YU%X$@2;(Q
  2312. M(*0@-0#0#GH7F#0L(E)%0T]21"`C(CM).R(](CM!)"A)*0#V#GP7F#0L(D%$
  2313. M1$E424].04P@24Y&3R`B.TD[(CTB.T,D*$DI`/X.?Q>"($D`"`^$%Z`@-#J.
  2314. M`%(/6!N/(%1/(%)%040@24X@4D5#3U)$4R!)3B!2159%4E-%($]21$52(%)%
  2315. M34]612!42$4@4D5-($E.($Q)3D4@(S$Q-2!!3D0`<@]:&X\@4%54($$@4D5-
  2316. M($)%1D]212!,24Y%(S$Q,`"^#UT;CR!43R!214%$(%1(12`Q4U0@1DE%3$0@
  2317. M3T8@5$A%(#%35"!214-/4D0@04Y$(%1(12`R3D0@1DE%3$0@3T8@5$A%($Q!
  2318. M4U0`\0]?&X\@4D503$%#12!42$4@0TA2)"A)*2!)3B!,24Y%(#$W-R!7251(
  2319. M($-(4B0H2RD`(1!`'YD@(E=(24-((%)%0T]21"`C($1/(%E/52!704Y4(%)%
  2320. M4$Q!0T5$(CJ%($D`0!!!'X4@(D5.5$52($Y%5R!214-/4D0B.T$D*$DI`'<0
  2321. M0A^8,2PB4"(@QR@RJCDV*<<H22G'*#`IQR@Q*3J/(%!/4TE424].($9)3$4@
  2322. M4$])3E1%4@"$$$,?F#(L020H22D`K1!$'X4@(D5.5$52($Y%5R!214-/4D0@
  2323. M*$9)14Q$(#(I(CM#)"A)*0#E$$4?F#$L(E`B(,<H,JHY-BG'*$DIQR@P*<<H
  2324. M,C4I.H\@4$]3251)3TX@1DE,12!03TE.5$52`/(01Q^8,BQ#)"A)*0`9$4D?
  2325. KF2`B4D5#3U)$(R([23LB($A!4R!"145.(%)%4$Q!0T5$(@`?$4H?C@``````
  2326. `
  2327. end
  2328.  
  2329.  
  2330.  
  2331. 7.4 CREATE A RELATIVE FILE
  2332.  
  2333. The program below, creates a relative file with 2 fields.  The first
  2334. field starts in position 1 of the record and the second field starts
  2335. in position 25.
  2336.  
  2337. LINE 8: Create the file.  Make room for records of 50 characters with
  2338. the CHR$(50). Use the Z$ as a file, input variable in LINE 6, you can
  2339. then press the f1 function key to create a file.
  2340.  
  2341. LINE 30: Point to the first character position of a file.  P tells the
  2342. disk drive to point to the position in the record that corresponds to
  2343. the optional, CHR$(1).
  2344.  
  2345. NOTE: If the CHR$ is not specified, character position defaults to 1.
  2346.  
  2347. LINE 65: Point to the twenty-fifth character position of a file.  P
  2348. tells the disk drive to point to the position in the record that
  2349. corresponds to the CHR$(25).
  2350.  
  2351. NOTE: The POSITION command does NOT write anything to, or read
  2352. anything from the file.  It just points to the position specified in
  2353. the record.
  2354.  
  2355. WRITE TO A RELATIVE FILE
  2356.  
  2357. LINE 60: Use the PRINT# statement after the POSITION command to move
  2358. to character position 1, as specified in LINE 30 -- CHR$(1).
  2359.  
  2360. READ FROM A RELATIVE FILE
  2361.  
  2362. LINE 130: Specify the character position using the POSITION command.
  2363. Then follow it with LINE 160, the INPUT# statement.
  2364.  
  2365. 7.5 SUMMARY
  2366.  
  2367. In this program, you press the f1 key and a RELative file is created
  2368. on disk.  You can type RUN and press the f3 key to READ the previous
  2369. RELative file.  If an error condition exists (flashing red light on
  2370. the disk drive) you can hit the RUN/STOP key, type RUN and press the
  2371. f5 key.  This reads the ERROR CHANNEL from the drive, shows the error
  2372. number and message, as well as the track and sector of the error.  It
  2373. then resets the drive for use.  Later on the program asks if the file
  2374. should be printed.  To Print the file, press the f7 key when prompted,
  2375. or press C to continue.
  2376.  
  2377. REMEMBER:
  2378.  
  2379. 1) Before a file can be written to, or read from, a POSITION command
  2380. must be executed.
  2381.  
  2382. 2) You must always use PRINT#1 with the POSITION command. This puts
  2383. your data under command channel control.
  2384.  
  2385. 3) The FIRST character string code in the POSITION command must
  2386. correspond to the THIRD number (channel #) in the OPEN statement.
  2387. Except OPEN 1, 8, 15 (see lines 8 and 30 of above program).
  2388.  
  2389. 4) For convenience, use the FOR ... NEXT loop variable in the SECOND
  2390. character string, CHR$(I), of the POSITION command where I equals the
  2391. record number (see lines 20 and 30 of above program).
  2392.  
  2393. 7.6 MODIFYING THE PROGRAM
  2394.  
  2395. 1) You can add more POSITION commands to make more fields within each
  2396. record. Remember to include the character position number as the last
  2397. CHR$, when adding fields.
  2398.  
  2399. 2) To change the length of each record, change the value of CHR$(50)
  2400. in LINE 8.
  2401.  
  2402. 3) The number of records in the file is determined by the POSITION
  2403. command. The current example can process 5 records; the FOR ... NEXT
  2404. loop variable is 1 to 5. The program can process 720 records, but in
  2405. order to use more than 512 records, the number 2 must be in the THIRD
  2406. CHR$() of the POSITION command.  For more than 256, use the number 1.
  2407. For up to 256 records, simply use the FOR ... NEXT loop variable.
  2408. EXAMPLE: FOR I=1 TO 256 may access 256 records.
  2409.  
  2410.  
  2411.  
  2412. 8. PROGRAMMING THE DISK CONTROLLER
  2413.  
  2414. The expert programmer can actually design routines that reside and
  2415. operate on the disk controller.  DOS routines can be added that come
  2416. from the diskette.  Routines can be added much the same way as the DOS
  2417. Support Program is "wedged" into your memory.
  2418.  
  2419. 8.1 BLOCK-EXECUTE
  2420.  
  2421. This command will load a block from the diskette containing a machine
  2422. language routine, and begin executing it at location 0 in the buffer
  2423. until a RTS (ReTurn from Subroutine) command is encountered.
  2424.  
  2425. FORMAT FOR BLOCK-EXECUTE:
  2426.  
  2427.     PRINT#file#, "B-E:" channel; drive; track; block
  2428.  
  2429.  
  2430.  
  2431. 8.2 MEMORY-READ
  2432.  
  2433. There is 16K of ROM in the disk drive as well as 2K of RAM.  You can
  2434. get direct access to these, or to the buffers that the DOS has set up
  2435. in the RAM, by using the MEMORY commands.  MEMORY-READ allows you to
  2436. select which byte to read, through the error channel.
  2437.  
  2438. FORMAT FOR MEMORY-READ:
  2439.  
  2440.     PRINT#file#, "M-R" CHR$(low byte of address) CHR$(high byte)
  2441.     (no abbreviation!)
  2442.  
  2443. The next byte read using the GET# statement through channel# 15, the
  2444. error channel, will be from that address in the disk controller's
  2445. memory, and successive bytes will be from successive memory locations.
  2446.  
  2447. Any INPUT# to the error channel will give peculiar results when you're
  2448. using this command.  This can be cleared up by any other command to
  2449. the disk (aside from a memory command).
  2450.  
  2451. PROGRAM TO READ THE DISK CONTROLLER'S MEMORY:
  2452.  
  2453. start tok64 rdiskmem.prg
  2454.  10 open 15,8,15
  2455.  20 input "location please";a
  2456.  25 for l=1 to 50
  2457.  30 a1=int(a/256):a2=a-a1*256
  2458.  40 print#15,"m-r" chr$(a2)chr$(a1)
  2459.  50 get#15,a$: rem get chars from error channel
  2460.  60 print asc(a$+chr$(0))
  2461.  70 a=a+1
  2462.  80 next
  2463.  90 input "continue";a$
  2464.  100 if left$(a$,1)="y" then 25
  2465.  110 goto 20
  2466. stop tok64
  2467.  
  2468. begin 644 RDISKMEM.PRG
  2469. M`0@/"`H`GR`Q-2PX+#$U`"D(%`"%("),3T-!5$E/3B!03$5!4T4B.T$`.`@9
  2470. M`($@3+(Q(*0@-3``5`@>`$$QLK4H0:TR-38I.D$RLD&K03&L,C4V`&T(*`"8
  2471. M,34L(DTM4B(@QRA!,BG'*$$Q*0"9"#(`H2,Q-2Q!)#H@CR!'150@0TA!4E,@
  2472. M1E)/32!%4E)/4B!#2$%.3D5,`*H(/`"9(,8H022JQR@P*2D`M`A&`$&R0:HQ
  2473. M`+H(4`""`,X(6@"%(")#3TY424Y512([020`Y0AD`(L@R"A!)"PQ*;(B62(@
  2474. 0IR`R-0#N"&X`B2`R,```````
  2475. `
  2476. end
  2477.  
  2478.  
  2479.  
  2480. 8.3 MEMORY-WRITE
  2481.  
  2482. The MEMORY-WRITE command allows you to write up to 34 bytes at a time
  2483. into the disk controller's memory.  The MEMORY-EXECUTE and USER
  2484. commands can be used to run this code.
  2485.  
  2486. FORMAT FOR MEMORY-WRITE:
  2487.  
  2488.     PRINT#file#, "M-W" CHR$(low address byte) CHR$(high address byte)
  2489.     CHR$(#-of-characters) byte data
  2490.  
  2491. PROGRAM TO WRITE AN "RTS" TO DISK:
  2492.  
  2493.  10 OPEN 8,8,15,"I": REM INITIALIZE DISK FIRST
  2494.  20 PRINT#8,"M-W" CHR$(0) CHR$(3) CHR$(1) CHR$(96)
  2495.  30 PRINT#8,"M-E" CHR$(0) CHR$(3)
  2496.  40 CLOSE 8
  2497.  
  2498.  
  2499.  
  2500. 8.4 MEMORY-EXECUTE
  2501.  
  2502. Any routine in the DOS memory, RAM or ROM, can be executed with the
  2503. MEMORY-EXECUTE command.
  2504.  
  2505. FORMAT FOR MEMORY-EXECUTE:
  2506.  
  2507.     PRINT#file#, "M-E" CHR$(low address byte) CHR$(high byte)
  2508.  
  2509. See line 30 above for an example.
  2510.  
  2511. 8.5 USER COMMANDS
  2512.  
  2513. Aside from the USER1 and USER2 commands discussed in chapter 6, and
  2514. the UI+ and UI- commands in chapter 2, the USER commands are jumps to
  2515. a table of locations in the disk drive's RAM memory.
  2516.  
  2517. USER COMMAND                    FUNCTION
  2518.  
  2519.  U1 or UA      BLOCK-READ without changing buffer-pointer
  2520.  U2 or UB      BLOCK-WRITE without changing buffer-pointer
  2521.  U3 or UC      jump to $0500  --+
  2522.  U4 or UD      jump to $0503    |
  2523.  U5 or UE      jump to $0506    |
  2524.  U6 or UF      jump to $0509    + (HEXADECIMAL LOCATIONS)
  2525.  U7 or UG      jump to $050C    |
  2526.  U8 or UH      jump to $05OF    |
  2527.  U9 or UI      jump to $FFFA  --+
  2528.  U; or UJ      power-up vector
  2529.  UI+           set Commodore 64 speed
  2530.  UI-           set VIC 20 speed
  2531.  
  2532. By loading these locations with another jump command, like JMP $0520,
  2533. you can create longer routines that operate in the disk's memory along
  2534. with an easy-to-use jump table -- even from BASIC!
  2535.  
  2536. EXAMPLES OF USER COMMANDS:
  2537.  
  2538.      PRINT# 15, "U3"
  2539.      PRINT# 15, "U"+CHR$(50+Q)
  2540.      PRINT# 15, "UI"
  2541.  
  2542.  
  2543.  
  2544. 9. CHANGING THE DISK DRIVE DEVICE NUM[BER
  2545.  
  2546. 9.1 SOFTWARE METHOD
  2547.  
  2548. The device number is selected by the drive by looking at a hardware
  2549. jumper on the board and writing the number based on that jumper in a
  2550. section of its RAM.  Once operation is underway, it is easy to write
  2551. over the previous device number with a new one.
  2552.  
  2553. FORMAT FOR CHANGING DEVICE NUMBER:
  2554.  
  2555.     PRINT#file#,"M-W:" CHR$(119) CHR$(0) CHR$(2) CHR$(address+32)
  2556.     CHR$(address+64)
  2557.  
  2558. EXAMPLE OF CHANGING DEVICE NUMBER (FROM 8 TO 9):
  2559.  
  2560.  10 OPEN 15, 8, 15
  2561.  20 PRINT# 15, "M-W" CHR$(119) CHR$(0) CHR$(2) CHR$(9+32)
  2562.     CHR$(9+64)
  2563.  
  2564. If you have more than one drive, it's sensible to change the address
  2565. through hardware (see below). If you must, the procedure is easy. Just
  2566. plug in the drives one at a time, and change their number to the
  2567. desired new values.  That way you won't have any conflicts.
  2568.  
  2569.  
  2570.  
  2571. 9.2 HARDWARE METHOD
  2572.  
  2573. It's an easy job to permanently change the device number of your drive
  2574. for use in multiple drive systems.  The tools needed are a phillips-
  2575. head screwdriver and a knife.
  2576.  
  2577. STEPS TO CHANGING DEVICE NUMBER ON HARDWARE:
  2578.  
  2579.   1. Disconnect all cables from drive, including power.
  2580.   2. Turn drive upside down on a flat, steady surface.
  2581.   3. Remove 4 screws holding drive box together.
  2582.   4. Carefully turn drive right side up, and remove case top.
  2583.   5. Remove 2 screws on side of metal housing.
  2584.   6. Remove housing.
  2585.   7. Locate device number jumpers. If facing the front of the
  2586.      drive, it's on the left edge in the middle of the board.
  2587.   8. Cut either or both of jumpers 1 and 2 for Model 1541.
  2588.      Cut either or both of jumpers A and B for Model 1541CR.
  2589.      (see chart below)
  2590.   9. Replace housing and 2 screws, and case top and 4 screws.
  2591.  10. Re-connect cables and power up.
  2592.  
  2593.       DEVICE#     |      JUMPER A/1    |     JUMPER B/2
  2594.  -----------------+--------------------+-------------------
  2595.            8      |      DON'T CUT     |     DON'T CUT
  2596.  -----------------+--------------------+-------------------
  2597.            9      |         CUT        |     DON'T CUT
  2598.  -----------------+--------------------+-------------------
  2599.           10      |      DON'T CUT     |       CUT
  2600.  -----------------+--------------------+-------------------
  2601.           11      |         CUT        |       CUT
  2602.  
  2603.  
  2604.  
  2605. 10. ASSEMBLY LANGUAGE AND THE 1541
  2606.  
  2607. If you want to use your 1541 disk drive to manipulate data directly
  2608. from assembly language you can use the information presented below.
  2609.  
  2610. Here is a list of subroutines that provide the start of memory
  2611. locations in each of the Kernal routines. These routines are used in
  2612. conjunction with the assembly language command JSR to jump to that
  2613. subroutine location in memory:
  2614.  
  2615.  SUBROUTINE
  2616.  SETLFS = $FFBA       ; set logical, physical & secondary addresses
  2617.  SETNAM = $FFBD       ; save length & address of filename
  2618.  OPEN   = SFFC0       ; open a logical file
  2619.  CLOSE  = $FFC3       ; close a logical file
  2620.  CHKIN  = $FFC6       ; open a channel for input
  2621.  CLRCH  = $FFCC       ; clear all channels
  2622.  BASIN  = $FFCF       ; get a byte from a file
  2623.  BSOUT  = $FFD2       ; output a character to the screen
  2624.  
  2625. For a more complete description as to what each routine does and what
  2626. parameters are passed to and from each routine, see your Commodore 64
  2627. or VIC-20 Programmer's Reference Guide.
  2628.  
  2629. Now, for a practical application of the subroutines listed above, here
  2630. is a sample program using those routines to read a sequential file on
  2631. a disk. Assume that you have stored the filename "TEST" at $C000.
  2632.  
  2633.  INIT                 ; initialize:
  2634.  LDA #$04             ; filename length
  2635.  LDX #$00             ; low byte of filename address
  2636.  LDY #$C0             ; high byte of filename address
  2637.  JSR SETNAM           ; save length & address of filename
  2638.  LDA #$03             ; logical address
  2639.  LDX #$08             ; device number
  2640.  LDY #$00             ; secondary address (0 = read seq. file)
  2641.  JSR SETLFS           ; set logical, physical & secondary addresses
  2642.  JSR OPEN             ; open logical file
  2643.  LDX #$03             ; set x-register to logical address
  2644.  JSR CHKIN            ; open input channel
  2645.  your program info    ; get data and print it one byte at a time
  2646.  JSR BASIN            ; get one byte
  2647.  BEQ END              ; if 0 then end of file or error
  2648.  JSR BSOUT            ; output character to the screen
  2649.  JMP your prog. info  ; loop
  2650.  END
  2651.  LDA #$03             ; set accumulator to logical address
  2652.  JSR CLOSE            ; close file
  2653.  JSR CLRCH            ; clear channels and reset defaults
  2654.  RTS                  ; end of assembly language program
  2655.  
  2656.  
  2657.  
  2658. APPENDIX A: DISK COMMAND SUMMARY
  2659.  
  2660. General Format: PRINT#file#, command
  2661.  
  2662.  COMMAND
  2663.  
  2664.  NEW                "N
  2665.  COPY               "C:new file=:orginal file
  2666.  RENAME             "R:new name=old name
  2667.  SCRATCH            "S:file name
  2668.  INITIALIZE         "I
  2669.  VALIDATE           "V
  2670.  DUPLICATE          not for single drives
  2671.  BLOCK-READ         "B-R:" channel; drive; track; block
  2672.  BLOCK-WRITE        "B-W:" channel; drive; track; block
  2673.  BLOCK-ALLOCATE     "B-A:" drive; track; block
  2674.  BLOCK-FREE         "B-F:" drive; track; block
  2675.  BUFFER-POINTER     "B-P:" channel; position
  2676.  USER1 and USER2    "Un:" channel; drive; track; block
  2677.  POSITION           "P" CHR$(channel#) CHR$(rec#lo) CHR$(rec#hi)
  2678.                      CHR$(position)
  2679.  BLOCK-EXECUTE      "B-E:" channel; drive; track; block
  2680.  MEMORY-READ        "M-R" CHR$(address lo) CHR$(address hi)
  2681.  MEMORY-WRITE       "M-W" CHR$(address lo) CHR$(address hi)
  2682.                     CHR$(#chars) "data"
  2683.  MEMORY-EXECUTE     "M-E" CHR$(address lo) CHR$(address hi)
  2684.  USER Commands      "Un"
  2685.  
  2686.  
  2687.  
  2688. APPENDIX B: SUMMARY OF CBM FLOPPY ERROR MESSAGES
  2689.  
  2690.  0         OK, no error exists.
  2691.  1         Files scratched response. Not an error condition.
  2692.  2-19      Unused error messages: should be ignored.
  2693.  20        Block header not found on disk.
  2694.  21        Sync character not found.
  2695.  22        Data block not present.
  2696.  23        Checksum error in data.
  2697.  24        Byte decoding error.
  2698.  25        Write-verify error.
  2699.  26        Attempt to write with write protect on.
  2700.  27        Checksum error in header.
  2701.  28        Data extends into next block.
  2702.  29        Disk id mismatch.
  2703.  30        General syntax error
  2704.  31        Invalid command.
  2705.  32        Long line.
  2706.  33        Invalid filename.
  2707.  34        No file given.
  2708.  39        Command file not found.
  2709.  50        Record not present.
  2710.  51        Overflow in record.
  2711.  52        File too large.
  2712.  60        File open for write.
  2713.  61        File not open.
  2714.  62        File not found.
  2715.  63        File exists.
  2716.  64        File type mismatch.
  2717.  65        No block.
  2718.  66        Illegal track or sector.
  2719.  67        Illegal system track or sector.
  2720.  70        No channels available.
  2721.  71        Directory error.
  2722.  72        Disk full or directory full.
  2723.  73        Power up message, or write attempt with DOS Mismatch.
  2724.  74        Drive not ready.
  2725.  
  2726. DESCRIPTION OF DOS ERROR MESSAGES
  2727.  
  2728. NOTE: Error message numbers less than 20 should be ignored with the
  2729. exception of 01 which gives information about the number of files
  2730. scratched with the SCRATCH command.
  2731.  
  2732. 20: READ ERROR (block header not found) -- The disk controller is
  2733. unable to locate the header of the requested data block. Caused by an
  2734. illegal block number, or the header has been destroyed.
  2735.  
  2736. 21: READ ERROR (no sync character) -- The disk controller is unable to
  2737. detect a sync mark on the desired track. Caused by misalignment of the
  2738. read/writer head, no diskette is present, or unformatted or improperly
  2739. seated diskette. Can also indicate a hardware failure.
  2740.  
  2741. 22: READ ERROR (data block not present) -- The disk controller has
  2742. been requested to read or verify a data block that was not properly
  2743. written. This error message occurs in conjunction with the BLOCK
  2744. commands and indicates an illegal track and/or block request.
  2745.  
  2746. 23: READ ERROR (checksum error in data block) -- This error message
  2747. indicates that there is an error in one or more of the data bytes. The
  2748. data has been read into the DOS memory, but the checksum over the data
  2749. is in error. This message may also indicate grounding problems.
  2750.  
  2751. 24: READ ERROR (byte decoding error) -- The data or header as been
  2752. read into the DOS memory, but a hardware error has been created due to
  2753. an invalid bit pattern in the data byte. This message may also
  2754. indicate grounding problems.
  2755.  
  2756. 25: WRITE ERROR (write-verify error) -- This message is generated if
  2757. the controller detects a mismatch between the written data and the
  2758. data in the DOS memory.
  2759.  
  2760. 26: WRITE PROTECT ON -- This message is generated when the controller
  2761. has been requested to write a data block while the write protect
  2762. switch is depressed. Typically, this is caused by using a diskette
  2763. with a write a protect tab over the notch.
  2764.  
  2765. 27: READ ERROR (checksum error in header) -- The controller has
  2766. detected an error in the header of the requested data block. The block
  2767. has not been read into the DOS memory.  This message may also indicate
  2768. grounding problems.
  2769.  
  2770. 28: WRITE ERROR (long data block) -- The controller attempts to detect
  2771. the sync mark of the next header after writing a data block. If the
  2772. sync mark does not appear within a predetermined time, the error
  2773. message is generated.  The error is caused by a bad diskette format
  2774. (the data extends into the next block), or by hardware failure.
  2775.  
  2776. 29: DISK ID MISMATCH -- This message is generated when the controller
  2777. has been requested to access a diskette which has not been initialized.
  2778. The message can also occur if a diskette has a bad header.
  2779.  
  2780. 30: SYNTAX ERROR (general syntax) -- The DOS cannot interpret the
  2781. command sent to the command channel.  Typically, this is caused by an
  2782. illegal number of file names, or pattems are illegally used. For
  2783. example, two file names may appear on the left side of the COPY
  2784. command.
  2785.  
  2786. 31: SYNTAX ERROR (invalid command) -- The DOS does not recognize the
  2787. command.  The command must start in the first position.
  2788.  
  2789. 32: SYNTAX ERROR (invalid command) -- The command sent is longer than
  2790. 58 characters.
  2791.  
  2792. 33: SYNTAX ERROR (invalid file name) -- Pattem matching is invalidly
  2793. used in the OPEN or SAVE command.
  2794.  
  2795. 34: SYNTAX ERROR (no file given) -- the file name was left out of a
  2796. command or the DOS does not recognize it as such.  Typically, a colon
  2797. (:) has been left out of the command,
  2798.  
  2799. 39: SYNTAX ERROR (invalid command) -- This error may result if the
  2800. command sent to command channel (secondary address 15) is unrecognized
  2801. by the DOS.
  2802.  
  2803. 50: RECORD NOT PRESENT -- Result of disk reading past the last record
  2804. through INPUT#, or GET# commands.  This message will also occur after
  2805. positioning to a record beyond end of file in a relative file.  If the
  2806. intent is to expand the file by adding the new record (with a PRINT#
  2807. command), the error message may be ignored.  INPUT or GET should not
  2808. be attempted after this error is detected without first repositioning.
  2809.  
  2810. 51: OVERFLOW IN RECORD -- PRINT# statement exceeds record boundary.
  2811. Information is cut off.  Since the carriage return is sent as a record
  2812. terminator is counted in the record size.  This message will occur if
  2813. the total characters in the record (including the final carriage
  2814. return) exceeds the defined size.
  2815.  
  2816. 52: FILE TOO LARGE -- Record position within a relative file indicates
  2817. that disk overflow will result.
  2818.  
  2819. 60: WRITE FILE OPEN -- This message is generated when a write file
  2820. that has not been closed is being opened for reading.
  2821.  
  2822. 61: FILE NOT OPEN -- This message is generated when a file is being
  2823. accessed that has not been opened in the DOS.  Sometimes, in this case,
  2824. a message is not generated; the request is simply ignored.
  2825.  
  2826. 62: FILE NOT FOUND -- The requested file does not exist on the
  2827. indicated drive.
  2828.  
  2829. 63: FILE EXISTS -- The file name of the file being created already
  2830. exists on the diskette.
  2831.  
  2832. 64: FILE TYPE MISMATCH -- The file type does not match the file type
  2833. in the directory entry for the requested file.
  2834.  
  2835. 65: NO BLOCK -- This message occurs in conjunction with the B-A
  2836. command.  It indicates that the block to be allocated has been
  2837. previously allocated.  The parameters indicate the track and sector
  2838. available with the next highest number.  If the parameters are zero
  2839. (0), then all blocks higher in number are in use.
  2840.  
  2841. 66: ILLEGAL TRACK AND SECTOR -- The DOS has attempted to access a
  2842. track or block which does not exist in the format being used.  This
  2843. may indicate a problem reading the pointer to the next block.
  2844.  
  2845. 67: ILLEGAL SYSTEM T OR S -- This special error message indicates an
  2846. illegal system track or block.
  2847.  
  2848. 70: NO CHANNEL (available) -- The requested channel is not available,
  2849. or all channels are in use.  A maximum of five sequential files may be
  2850. opened at one time to the DOS.  Direct access channels may have six
  2851. opened files.
  2852.  
  2853. 71: DIRECTORY ERROR -- The BAM does not match the internal count.
  2854. There is a problem in the BAM allocation or the BAM has been
  2855. overwritten in DOS memory.  To correct this problem, reinitialize the
  2856. diskette to restore the BAM in memory.  Some active files may be
  2857. terminated by the corrective action.  NOTE: BAM = Block Availability
  2858. Map
  2859.  
  2860. 72: DISK FULL -- Either the blocks on the diskette are used or the
  2861. directory is at its entry limit. DISK FULL is sent when two blocks are
  2862. available on the 1541 to allow the current file to be closed.
  2863.  
  2864. 73: DOS MISMATCH (73, CBM DOS V2.6 1541) -- DOS 1 and 2 are read
  2865. compatible but not write compatible.  Disks may be interchangeably
  2866. read with either DOS, but a disk formatted on one version cannot be
  2867. written upon with the other version because the format is different.
  2868. This error is displayed whenever an attempt is made to write upon a
  2869. disk which has been formatted in a non-compatible format. (A utility
  2870. routine is available to assist in converting from one format to
  2871. another.) This message may also appear after power up.
  2872.  
  2873. 74: DRIVE NOT READY -- An attempt has been made to access the 1541
  2874. Single Drive Floppy Disk without any diskettes present in either drive.
  2875.  
  2876.  
  2877.  
  2878. APPENDIX C: Demonstration Disk Programs
  2879.  
  2880. 1. DIR
  2881.  
  2882. start tok64 dir.prg
  2883.  4 open 2,8,15
  2884.  5 print "{clear}":goto 10000
  2885.  10 open 1,8,0,"$0"
  2886.  20 get#1,a$,b$
  2887.  30 get#1,a$,b$
  2888.  40 get#1,a$,b$
  2889.  50 c=0
  2890.  60 if a$<>"" then c=asc(a$)
  2891.  70 if b$<>"" then c=c+asc(b$)*256
  2892.  80 print "{reverse on}" mid$(str$(c),2);tab(3);"{reverse off}";
  2893.  90 get#1,b$:if st<>0 then 1000
  2894.  100 if b$<>chr$(34) then 90
  2895.  110 get#1,b$:if b$<>chr$(34)then printb$;:goto110
  2896.  120 get#1,b$:if b$=chr$(32) then 120
  2897.  130 print tab(18);:c$=""
  2898.  140 c$=c$+b$:get#1,b$:if b$<>"" then 140
  2899.  150 print "{reverse on}" left$(c$,3)
  2900.  160 get t$:if t$<>"" then gosub 2000
  2901.  170 if st=0 then 30
  2902.  1000 print" blocks free"
  2903.  1010 close 1:goto 10000
  2904.  2000 if t$="q" then close 1:end
  2905.  2010 get t$:if t$="" then 2000
  2906.  2020 return
  2907.  4000 rem disk command
  2908.  4010 c$="":print">";
  2909.  4011 get b$:if b$="" then 4011
  2910.  4012 print b$;:if b$=chr$(13) then 4020
  2911.  4013 c$=c$+b$:goto 4011
  2912.  4020 print#2,c$
  2913.  5000 print "{reverse on}";
  2914.  5010 get#2,a$:print a$;:if a$<>chr$(13) goto 5010
  2915.  5020 print "{reverse off}"
  2916.  10000 print "d-directory"
  2917.  10010 print ">-disk command"
  2918.  10020 print "q-quit program"
  2919.  10030 print "s-disk status"
  2920.  10100 get a$:if a$="" then 10100
  2921.  10200 if a$="d" then 10
  2922.  10300 if a$="." or a$=">" then 4000
  2923.  10310 if a$="q" then end
  2924.  10320 if a$="s" then 5000
  2925.  10999 goto 10100
  2926. stop tok64
  2927.  
  2928. begin 644 DIR.PRG
  2929. M`0@."`0`GR`R+#@L,34`(`@%`)D@(I,B.HD@,3`P,#``,0@*`)\@,2PX+#`L
  2930. M(B0P(@`_"!0`H2,Q+$$D+$(D`$T('@"A(S$L020L0B0`6P@H`*$C,2Q!)"Q"
  2931. M)`!C"#(`0[(P`'H(/`"+($$DL[$B(B"G($.RQBA!)"D`EPA&`(L@0B2SL2(B
  2932. M(*<@0[)#JL8H0B0IK#(U-@"T"%``F2`B$B(@RBC$*$,I+#(I.Z,S*3LBDB([
  2933. M`,X(6@"A(S$L0B0ZBR!35+.Q,""G(#$P,#``XPAD`(L@0B2SL<<H,S0I(*<@
  2934. M.3``!0EN`*$C,2Q")#J+($(DL[''*#,T*:<@F4(D.SJ),3$P`"$)>`"A(S$L
  2935. M0B0ZBR!")++'*#,R*2"G(#$R,``S"8(`F2"C,3@I.SI#)+(B(@!6"8P`0R2R
  2936. M0R2J0B0ZH2,Q+$(D.HL@0B2SL2(B(*<@,30P`&@)E@"9("(2(B#(*$,D+#,I
  2937. M`(,)H`"A(%0D.HL@5"2SL2(B(*<@C2`R,#`P`),)J@"+(%-4LC`@IR`S,`"G
  2938. M">@#F2(@0DQ/0TM3($92144B`+<)\@.@(#$ZB2`Q,#`P,`#,"=`'BR!4)+(B
  2939. M42(@IR"@(#$Z@`#D"=H'H2!4)#J+(%0DLB(B(*<@,C`P,`#J">0'C@#]":`/
  2940. MCR!$25-+($-/34U!3D0`#0JJ#T,DLB(B.IDB/B([`"4*JP^A($(D.HL@0B2R
  2941. M(B(@IR`T,#$Q`$$*K`^9($(D.SJ+($(DLL<H,3,I(*<@-#`R,`!5"JT/0R2R
  2942. M0R2J0B0ZB2`T,#$Q`%\*M`^8,BQ#)`!J"H@3F2`B$B([`(X*DA.A(S(L020Z
  2943. MF2!!)#LZBR!!)+.QQR@Q,RD@B2`U,#$P`)@*G!.9("*2(@"L"A`GF2`B1"U$
  2944. M25)%0U1/4EDB`,,*&B>9("(^+41)4TL@0T]-34%.1"(`V@HD)YD@(E$M455)
  2945. M5"!04D]'4D%-(@#P"BXGF2`B4RU$25-+(%-405154R(`"0MT)Z$@020ZBR!!
  2946. M)+(B(B"G(#$P,3`P`!L+V">+($$DLB)$(B"G(#$P`#@+/"B+($$DLB(N(B"P
  2947. M($$DLB(^(B"G(#0P,#``20M&*(L@022R(E$B(*<@@`!="U`HBR!!)+(B4R(@
  2948. 5IR`U,#`P`&D+]RJ)(#$P,3`P````
  2949. `
  2950. end
  2951.  
  2952.  
  2953. 2. VIEW BAM
  2954.  
  2955. start tok64 viewbam.prg
  2956.  100 rem********************************
  2957.  101 rem*  view bam for vic & 64 disk  *
  2958.  102 rem********************************
  2959.  105 open 15,8,15
  2960.  110 print#15,"i0":nu$="n/a n/a n/a n/a n/a":z4=1
  2961.  120 open 2,8,2,"#"
  2962.  130 y$="{home}{down*24}"
  2963.  140 x$="{right*23}"
  2964.  150 def fn s(z)=2^(s-int(s/8)*8) and (sb(int(s/8)))
  2965.  160 print#15,"u1:";2;0;18;0
  2966.  170 print#15,"b-p";2;1
  2967.  180 print "{clear}";
  2968.  190 y=22:x=1:gosub 430
  2969.  200 for i=0 to 20:print:print "{up*2}" right$(str$(i)+" ",3);:next
  2970.  210 get#2,a$
  2971.  220 get#2,a$
  2972.  230 get#2,a$
  2973.  240 ts=0
  2974.  250 for t=1 to 17:gosub 450
  2975.  260 y=22:x=t+4:gosub 430:gosub 540:next
  2976.  270 for i=1 to 2000:next:print "{clear}"
  2977.  280 y=22:x=1:gosub 430
  2978.  290 for i=0 to 20:print:print "{up*2}" right$(str$(i)+" ",3);:next
  2979.  300 for t=18 to 35
  2980.  310 gosub 450
  2981.  320 y=22:x=t-13:gosub 430:gosub 540:next
  2982.  330 for i=1 to 1000:next
  2983.  340 print "{clear}{down*5}"
  2984.  350 print#15,"b-p";2;144
  2985.  360 n$="":for i=1 to 20:get#2,a$:n$=n$+a$:next
  2986.  370 print" "n$" "ts-17;"blocks free"
  2987.  380 for i=1 to 4000:next
  2988.  390 print "{clear}"
  2989.  400 input "{down*3}{right*2}another diskette {right*2}n{left*3}";a$
  2990.  410 if a$="y" then run
  2991.  420 if a$<>"y" then end
  2992.  430 print left$(y$,y)left$(x$,x)"{left}";
  2993.  440 return
  2994.  450 get#2,sc$:sc=asc(right$(chr$(0)+sc$,1))
  2995.  460 ts=ts+sc
  2996.  470 get#2,a$:if a$="" then a$=chr$(0)
  2997.  480 sb(0)=asc(a$)
  2998.  490 get#2,a$:if a$="" then a$=chr$(0)
  2999.  500 sb(1)=asc(a$)
  3000.  510 get#2,a$:if a$="" then a$=chr$(0)
  3001.  520 sb(2)=asc(a$)
  3002.  530 return
  3003.  540 print "{down}{left}" right$(str$(t),1);"{left}{up*2}";
  3004.  550 rem  print t"   "sc"  "sb(0)" "sb(1)" "sb(2)=chr$(0)
  3005.  560 if t>24 and s=18 then:print mid$(nu$,z4,1);:goto 660
  3006.  570 for s=0 to 20
  3007.  580 if t<18 then 620
  3008.  590 if t>30 and s=17 then:print mid$(nu$,z4,1);:goto 660
  3009.  600 if t>24 and s=18 then:print mid$(nu$,z4,1);:goto 660
  3010.  610 if t>24 and s=19 then:print mid$(nu$,z4,1);:goto 660
  3011.  620 if t>17 and s=20 then:print mid$(nu$,z4,1);:z4=z4+1:goto 660
  3012.  630 print "{reverse on}";
  3013.  640 if fns(s)=0 then print "{";:goto 660
  3014.  650 print "{reverse off}{";:rem right$(str$(s),1);z4,1);:goto 72
  3015.  660 print "{up}{left}{reverse off}";
  3016.  670 next
  3017.  680 return
  3018. stop tok64
  3019.  
  3020. begin 644 VIEWBAM.PRG
  3021. M`0@G"&0`CRHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ`$T(90"/
  3022. M*B`@5DE%5R!"04T@1D]2(%9)0R`F(#8T($1)4TL@("H`<PAF`(\J*BHJ*BHJ
  3023. M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*@"!"&D`GR`Q-2PX+#$U`*T(;@"8
  3024. M,34L(DDP(CI.522R(DXO02!.+T$@3B]!($XO02!.+T$B.EHTLC$`O0AX`)\@
  3025. M,BPX+#(L(B,B`.`(@@!9)+(B$Q$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$2(`
  3026. M`0F,`%@DLB(='1T='1T='1T='1T='1T='1T='1T='2(`+`F6`)8@I2!3*%HI
  3027. MLC*N*%.KM2A3K3@IK#@I(*\@*%-"*+4H4ZTX*2DI`$,)H`"8,34L(E4Q.B([
  3028. M,CLP.S$X.S``50FJ`)@Q-2PB0BU0(CLR.S$`8`FT`)D@(I,B.P!S";X`6;(R
  3029. M,CI8LC$ZC2`T,S``G`G(`($@2;(P(*0@,C`ZF3J9("*1D2(@R2C$*$DIJB(@
  3030. M(BPS*3LZ@@"G"=(`H2,R+$$D`+()W`"A(S(L020`O0GF`*$C,BQ!)`#&"?``
  3031. M5%.R,`#;"?H`@2!4LC$@I"`Q-SJ-(#0U,`#X"00!6;(R,CI8LE2J-#J-(#0S
  3032. M,#J-(#4T,#J"`!$*#@&!($FR,2"D(#(P,#`Z@CJ9("*3(@`D"A@!6;(R,CI8
  3033. MLC$ZC2`T,S``30HB`8$@2;(P(*0@,C`ZF3J9("*1D2(@R2C$*$DIJB(@(BPS
  3034. M*3LZ@@!="BP!@2!4LC$X(*0@,S4`9PHV`8T@-#4P`(4*0`%9LC(R.EBR5*LQ
  3035. M,SJ-(#0S,#J-(#4T,#J"`)@*2@&!($FR,2"D(#$P,#`Z@@"G"E0!F2`BDQ$1
  3036. M$1$1(@"["EX!F#$U+")"+5`B.S([,30T`.(*:`%.)+(B(CJ!($FR,2"D(#(P
  3037. M.J$C,BQ!)#I.)+).)*I!)#J"``,+<@&9(B`B3B0B(")44ZLQ-SLB0DQ/0TM3
  3038. M($92144B`!8+?`&!($FR,2"D(#0P,#`Z@@`@"X8!F2`BDR(`2`N0`84@(A$1
  3039. M$1T=04Y/5$A%4B!$25-+151412`='4Z=G9TB.T$D`%D+F@&+($$DLB)9(B"G
  3040. M((H`:PND`8L@022SL2)9(B"G((``A`NN`9D@R"A9)"Q9*<@H6"0L6"DBG2([
  3041. M`(H+N`&.`*H+P@&A(S(L4T,D.E-#LL8HR2C'*#`IJE-#)"PQ*2D`MPO,`513
  3042. MLE13JE-#`-0+U@&A(S(L020ZBR!!)+(B(B"G($$DLL<H,"D`Y`O@`5-"*#`I
  3043. MLL8H020I``$,Z@&A(S(L020ZBR!!)+(B(B"G($$DLL<H,"D`$0ST`5-"*#$I
  3044. MLL8H020I`"X,_@&A(S(L020ZBR!!)+(B(B"G($$DLL<H,"D`/@P(`E-"*#(I
  3045. MLL8H020I`$0,$@*.`&`,'`*9("(1G2(@R2C$*%0I+#$I.R*=D9$B.P"7#"8"
  3046. MCR`@4%))3E0@5"(@("`B4T,B("`B4T(H,"DB(")30B@Q*2(@(E-"*#(I/4-(
  3047. M4B0H,"D`P`PP`HL@5+$R-""O(%.R,3@@ISJ9(,HH3E4D+%HT+#$I.SJ)(#8V
  3048. M,`#/##H"@2!3LC`@I"`R,`#@#$0"BR!4LS$X(*<@-C(P``D-3@*+(%2Q,S`@
  3049. MKR!3LC$W(*<ZF2#**$Y5)"Q:-"PQ*3LZB2`V-C``,@U8`HL@5+$R-""O(%.R
  3050. M,3@@ISJ9(,HH3E4D+%HT+#$I.SJ)(#8V,`!;#6("BR!4L3(T(*\@4[(Q.2"G
  3051. M.ID@RBA.520L6C0L,2D[.HD@-C8P`(P-;`*+(%2Q,3<@KR!3LC(P(*<ZF2#*
  3052. M*$Y5)"Q:-"PQ*3LZ6C2R6C2J,3J)(#8V,`"7#78"F2`B$B([`+0-@`*+(*53
  3053. M*%,ILC`@IR"9(")[(CLZB2`V-C``XPV*`ID@(I)[(CLZCR!224=(5"0H4U12
  3054. M)"A3*2PQ*3M:-"PQ*3LZ1T]43R`W,@#P#90"F2`BD9V2(CL`]@V>`H(`_`VH
  3055. %`HX`````
  3056. `
  3057. end
  3058.  
  3059.  
  3060. 3. DISPLAY T & S
  3061.  
  3062. start tok64 dispts.prg
  3063.  100 rem******************************
  3064.  110 rem* display any track $ sector *
  3065.  120 rem* on the disk to the screen  *
  3066.  130 rem* or the printer             *
  3067.  140 rem******************************
  3068.  150 print "{clear}{down*2}{175*22}"
  3069.  160 print "display block contents"
  3070.  165 print "{183*22}"
  3071.  170 rem******************************
  3072.  180 rem* set program constant       *
  3073.  190 rem******************************
  3074.  200 sp$=" ":nl$=chr$(0):hx$="0123456789abcdef"
  3075.  210 fs$="":for i=64 to 95:fs$=fs$+"{reverse on}"+chr$(i)+\
  3076.      "{reverse off}":next i
  3077.  220 ss$="  ":for i=192 to 223:ss$=ss$+"{reverse on}"+chr$(i)+\
  3078.      "{reverse off}":next i
  3079.  240 dim a$(15),nb(2)
  3080.  251 d$="0"
  3081.  253 print "        {reverse on}s{reverse off}creen{down}{left*8}";\
  3082.      "or {down}{left}{reverse on}p{reverse off}rinter"
  3083.  254 get jj$:if jj$="" then 254
  3084.  255 if jj$="s" then print "        {down}{reverse on}screen";\
  3085.      "{reverse off}"
  3086.  256 if jj$="p" then print "        {down}{reverse on}printer";\
  3087.      "{reverse off}"
  3088.  260 open 15,8,15,"i"+d$:gosub 650
  3089.  265 open 4,4
  3090.  270 open 2,8,2,"#":gosub 650
  3091.  280 rem******************************
  3092.  290 rem* load track and sector      *
  3093.  300 rem* into disk buffer           *
  3094.  310 rem******************************
  3095.  320 input "{down}{right*2}track, sector";t,s
  3096.  330 if t=0 or t>35 then print#15,"i"d$:close 2:close 4:close 15:\
  3097.      print "end":end
  3098.  340 if jj$="s" then print "{down}{right*2}track" t " sector" s \
  3099.      "{down}"
  3100.  341 if jj$="p" then print#4:print#4,"track" t " sector" s:print#4
  3101.  350 print#15,"u1:2," d$;t;s:gosub 650
  3102.  360 rem******************************
  3103.  370 rem* read byte 0 of disk buffer *
  3104.  390 rem******************************
  3105.  400 print#15,"b-p:2,1"
  3106.  410 print#15,"m-r"chr$(0)chr$(5)
  3107.  420 get#15,a$(0):if a$(0)="" then a$(0)=nl$
  3108.  428 if jj$="s" then 430
  3109.  430 if jj$="p"then 460
  3110.  431 rem******************************
  3111.  432 rem* read & crt display         *
  3112.  433 rem* rest of the disk buffer    *
  3113.  434 rem******************************
  3114.  436 k=1:nb(1)=asc(a$(0))
  3115.  438 for j=0 to 63:if j=32 then gosub 710:if z$="n" then j=80:\
  3116.      goto 458
  3117.  440 for i=k to 3
  3118.  442 get#2,a$(i):if a$(i)="" then a$(i)=nl$
  3119.  444 if k=1 and i<2 then nb(2)=asc(a$(i))
  3120.  446 next i:k=0
  3121.  448 a$="":b$=":":n=j*4:gosub 790:a$=a$+":"
  3122.  450 for i=0 to 3:n=asc(a$(i)):gosub 790
  3123.  452 c$=a$(i):gosub 850:b$=b$+c$
  3124.  454 next i:if jj$="s" then print a$b$
  3125.  458 next j:goto 571
  3126.  460 rem******************************
  3127.  462 rem* read & printer display     *
  3128.  464 rem******************************
  3129.  466 k=1:nb(1)=asc(a$(0))
  3130.  468 for j=0 to 15
  3131.  470 for i=k to 15
  3132.  472 get#2,a$(i):if a$(i)="" then a$(i)=nl$
  3133.  474 if k=1 and i<2 then nb(2)=asc(a$(i))
  3134.  476 next i:k=0
  3135.  478 a$="":b$=":":n=j*16:gosub 790:a$=a$+":"
  3136.  480 for i=0 to 15:n=asc(a$(i)):gosub 790:if z$="n" then j=40:\
  3137.      goto 571
  3138.  482 c$=a$(i):gosub 850:b$=b$+c$
  3139.  484 next i
  3140.  486 if jj$="p" then print#4,a$b$
  3141.  488 next j:goto 571
  3142.  571 rem******************************
  3143.  572 rem* next track and sector      *
  3144.  573 rem******************************
  3145.  575 print "next track and sector" nb(1) nb(2) "{down}"
  3146.  580 print "do you want next track and sector"
  3147.  590 get z$:if z$="" then 590
  3148.  600 if z$="y" then t=nb(1):s=nb(2):goto 330
  3149.  610 if z$="n" then 320
  3150.  620 goto 590
  3151.  630 rem******************************
  3152.  640 rem* subroutines                *
  3153.  650 rem******************************
  3154.  660 rem* error routine              *
  3155.  670 rem******************************
  3156.  680 input#15,en,em$,et,es:if en=0 then return
  3157.  690 print "{reverse on}disk error{reverse off}" en,em$,et,es
  3158.  700 end
  3159.  710 rem******************************
  3160.  720 rem* screen continue message    *
  3161.  730 rem******************************
  3162.  740 print "{down}{right*4}continue(y/n)"
  3163.  750 get z$:if z$="" then 750
  3164.  760 if z$="n" then return
  3165.  770 if z$<>"y" then 750
  3166.  780 print "{clear}track" t " sector" s "{home}":return
  3167.  790 rem******************************
  3168.  800 rem* disk byte to hex print     *
  3169.  810 rem******************************
  3170.  820 a1=int(n/16):a$=a$+mid$(hx$,a1+1,1)
  3171.  830 a2=int(n-16*a1):a$=a$+mid$(hx$,a2+1,1)
  3172.  840 a$=a$+sp$:return
  3173.  850 rem******************************
  3174.  860 rem* disk byte to asc display   *
  3175.  870 rem* character                  *
  3176.  880 rem******************************
  3177.  890 if asc(c$)<32 then c$=" ":return
  3178.  910 if asc(c$)<128 or asc(c$)>159 then return
  3179.  920 c$=mid$(ss$,3*(asc(c$)-127),3):return
  3180. stop tok64
  3181.  
  3182. begin 644 DISPTS.PRG
  3183. M`0@E"&0`CRHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*@!)"&X`CRH@
  3184. M1$E34$Q!62!!3ED@5%)!0TL@)"!314-43U(@*@!M"'@`CRH@3TX@5$A%($1)
  3185. M4TL@5$\@5$A%(%-#4D5%3B`@*@"1"((`CRH@3U(@5$A%(%!224Y415(@("`@
  3186. M("`@("`@("`@*@"U"(P`CRHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ
  3187. M*@#7")8`F2`BDQ$1KZ^OKZ^OKZ^OKZ^OKZ^OKZ^OKZ^OKR(`]@B@`)D@(D1)
  3188. M4U!,05D@0DQ/0TL@0T].5$5.5%,B`!4)I0"9("*WM[>WM[>WM[>WM[>WM[>W
  3189. MM[>WM[>W(@`Y":H`CRHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*@!=
  3190. M";0`CRH@4T54(%!23T=204T@0T].4U1!3E0@("`@("`@*@"!";X`CRHJ*BHJ
  3191. M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*@"M"<@`4U`DLB(@(CI.3"2RQR@P
  3192. M*3I(6"2R(C`Q,C,T-38W.#E!0D-$148B`-T)T@!&4R2R(B(Z@2!)LC8T(*0@
  3193. M.34Z1E,DLD93)*HB$B*JQRA)*:HBDB(Z@B!)`!$*W`!34R2R(B`@(CJ!($FR
  3194. M,3DR(*0@,C(S.E-3)+)34R2J(A(BJL<H22FJ(I(B.H(@20`D"O``AB!!)"@Q
  3195. M-2DL3D(H,BD`+PK[`$0DLB(P(@!B"OT`F2`B("`@("`@("`24Y)#4D5%3A&=
  3196. MG9V=G9V=G2([(D]2(!&=$E"24DE.5$52(@!["OX`H2!*2B0ZBR!*2B2R(B(@
  3197. MIR`R-30`I`K_`(L@2DHDLB)3(B"G()D@(B`@("`@("`@$1)30U)%14XB.R*2
  3198. M(@#."@`!BR!*2B2R(E`B(*<@F2`B("`@("`@("`1$E!224Y415(B.R*2(@#I
  3199. M"@0!GR`Q-2PX+#$U+"))(JI$)#J-(#8U,`#S"@D!GR`T+#0`"0L.`9\@,BPX
  3200. M+#(L(B,B.HT@-C4P`"T+&`&/*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ
  3201. M*BHJ`%$+(@&/*B!,3T%$(%1204-+($%.1"!314-43U(@("`@("`J`'4++`&/
  3202. M*B!)3E1/($1)4TL@0E5&1D52("`@("`@("`@("`J`)D+-@&/*BHJ*BHJ*BHJ
  3203. M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ`+8+0`&%("(1'1U44D%#2RP@4T5#5$]2
  3204. M(CM4+%,`Z@M*`8L@5+(P(+`@5+$S-2"G()@Q-2PB22)$)#J@(#(ZH"`T.J`@
  3205. M,34ZF2`B14Y$(CJ``!@,5`&+($I*)+(B4R(@IR"9("(1'1U44D%#2R(@5"`B
  3206. M(%-%0U1/4B(@4R(1(@!'#%4!BR!*2B2R(E`B(*<@F#0ZF#0L(E1204-+(B!4
  3207. M("(@4T5#5$]2(B!3.I@T`&0,7@&8,34L(E4Q.C(L(B!$)#M4.U,ZC2`V-3``
  3208. MB`QH`8\J*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BH`K`QR`8\J(%)%
  3209. M040@0EE412`P($]&($1)4TL@0E5&1D52("H`T`R&`8\J*BHJ*BHJ*BHJ*BHJ
  3210. M*BHJ*BHJ*BHJ*BHJ*BHJ*BH`X@R0`9@Q-2PB0BU0.C(L,2(`^`R:`9@Q-2PB
  3211. M32U2(L<H,"G'*#4I`!X-I`&A(S$U+$$D*#`I.HL@020H,"FR(B(@IR!!)"@P
  3212. M*;).3"0`,@VL`8L@2DHDLB)3(B"G(#0S,`!%#:X!BR!*2B2R(E`BIR`T-C``
  3213. M:0VO`8\J*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BH`C0VP`8\J(%)%
  3214. M040@)B!#4E0@1$E34$Q!62`@("`@("`@("H`L0VQ`8\J(%)%4U0@3T8@5$A%
  3215. M($1)4TL@0E5&1D52("`@("H`U0VR`8\J*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ
  3216. M*BHJ*BHJ*BH`[`VT`4NR,3I.0B@Q*;+&*$$D*#`I*0`@#K8!@2!*LC`@I"`V
  3217. M,SJ+($JR,S(@IR"-(#<Q,#J+(%HDLB).(B"G($JR.#`ZB2`T-3@`+@ZX`8$@
  3218. M2;)+(*0@,P!3#KH!H2,R+$$D*$DI.HL@020H22FR(B(@IR!!)"A)*;).3"0`
  3219. M=`Z\`8L@2[(Q(*\@2;,R(*<@3D(H,BFRQBA!)"A)*2D`@`Z^`8(@23I+LC``
  3220. MIP[``4$DLB(B.D(DLB(Z(CI.LDJL-#J-(#<Y,#I!)+)!)*HB.B(`Q@["`8$@
  3221. M2;(P(*0@,SI.LL8H020H22DI.HT@-SDP`.(.Q`%#)+)!)"A)*3J-(#@U,#I"
  3222. M)+)")*I#)`#]#L8!@B!).HL@2DHDLB)3(B"G()D@021")``+#\H!@B!*.HD@
  3223. M-3<Q`"\/S`&/*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ`%,/S@&/
  3224. M*B!214%$("8@4%))3E1%4B!$25-03$%9("`@("`J`'</T`&/*BHJ*BHJ*BHJ
  3225. M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ`(X/T@%+LC$Z3D(H,2FRQBA!)"@P*2D`
  3226. MG0_4`8$@2K(P(*0@,34`K`_6`8$@2;)+(*0@,34`T0_8`:$C,BQ!)"A)*3J+
  3227. M($$D*$DILB(B(*<@020H22FR3DPD`/(/V@&+($NR,2"O($FS,B"G($Y"*#(I
  3228. MLL8H020H22DI`/X/W`&"($DZ2[(P`"80W@%!)+(B(CI")+(B.B(Z3K)*K#$V
  3229. M.HT@-SDP.D$DLD$DJB(Z(@!<$.`!@2!)LC`@I"`Q-3I.LL8H020H22DI.HT@
  3230. M-SDP.HL@6B2R(DXB(*<@2K(T,#J)(#4W,0!X$.(!0R2R020H22DZC2`X-3`Z
  3231. M0B2R0B2J0R0`@!#D`8(@20"8$.8!BR!*2B2R(E`B(*<@F#0L021")`"F$.@!
  3232. M@B!*.HD@-3<Q`,H0.P*/*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ
  3233. M`.X0/`*/*B!.15A4(%1204-+($%.1"!314-43U(@("`@("`J`!(1/0*/*BHJ
  3234. M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ`$`1/P*9(").15A4(%1204-+
  3235. M($%.1"!314-43U(B($Y"*#$I($Y"*#(I("(1(@!J$40"F2`B1$\@64]5(%=!
  3236. M3E0@3D585"!44D%#2R!!3D0@4T5#5$]2(@"!$4X"H2!:)#J+(%HDLB(B(*<@
  3237. M-3DP`*816`*+(%HDLB)9(B"G(%2R3D(H,2DZ4[).0B@R*3J)(#,S,`"Y$6("
  3238. MBR!:)+(B3B(@IR`S,C``PQ%L`HD@-3DP`.<1=@*/*BHJ*BHJ*BHJ*BHJ*BHJ
  3239. M*BHJ*BHJ*BHJ*BHJ*BHJ``L2@`*/*B!354)23U5424Y%4R`@("`@("`@("`@
  3240. M("`@("`J`"\2B@*/*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ`%,2
  3241. ME`*/*B!%4E)/4B!23U5424Y%("`@("`@("`@("`@("`J`'<2G@*/*BHJ*BHJ
  3242. M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ`)<2J`*$,34L14XL14TD+$54+$53
  3243. M.HL@14ZR,""G((X`N1*R`ID@(A)$25-+($524D]2DB(@14XL14TD+$54+$53
  3244. M`+\2O`*``.,2Q@*/*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ``<3
  3245. MT`*/*B!30U)%14X@0T].5$E.544@34534T%'12`@("`J`"L3V@*/*BHJ*BHJ
  3246. M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ`$83Y`*9("(1'1T='4-/3E1)3E5%
  3247. M*%DO3BDB`%T3[@*A(%HD.HL@6B2R(B(@IR`W-3``;A/X`HL@6B2R(DXB(*<@
  3248. MC@""$P(#BR!:)+.Q(EDB(*<@-S4P`*43#`.9("*35%)!0TLB(%0@(B!314-4
  3249. M3U(B(%,@(A,B.HX`R1,6`X\J*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ
  3250. M*BH`[1,@`X\J($1)4TL@0EE412!43R!(15@@4%))3E0@("`@("H`$10J`X\J
  3251. M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BH`-!0T`T$QLK4H3JTQ-BDZ
  3252. M022R022JRBA(6"0L03&J,2PQ*0!:%#X#03*RM2A.JS$VK$$Q*3I!)+)!)*K*
  3253. M*$A8)"Q!,JHQ+#$I`&H42`-!)+)!)*I34"0ZC@".%%(#CRHJ*BHJ*BHJ*BHJ
  3254. M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*@"R%%P#CRH@1$E32R!"651%(%1/($%30R!$
  3255. M25-03$%9("`@*@#6%&8#CRH@0TA!4D%#5$52("`@("`@("`@("`@("`@("`@
  3256. M*@#Z%'`#CRHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*@`4%7H#BR#&
  3257. M*$,D*;,S,B"G($,DLB(@(CJ.`#05C@.+(,8H0R0ILS$R.""P(,8H0R0IL3$U
  3258. H.2"G((X`5!68`T,DLLHH4U,D+#.L*,8H0R0IJS$R-RDL,RDZC@``````
  3259. `
  3260. end
  3261.  
  3262.  
  3263. 4. CHECK DISK
  3264.  
  3265. start tok64 chekdisk.prg
  3266.  1 rem check disk -- ver 1.4
  3267.  2 dn=8:rem floppy device number
  3268.  5 dim t(100):dim s(100):rem bad track, sector array
  3269.  9 print "{clear}{down*3}{175*21}"
  3270.  10 print " check disk program"
  3271.  12 print "{183*21}"
  3272.  20 d$="0"
  3273.  30 open 15,dn,15
  3274.  35 print#15,"v"d$
  3275.  45 n%=rnd(ti)*255
  3276.  50 a$="":for i=1 to 255:a$=a$+chr$(255 and (i+n%)):next
  3277.  60 gosub 900
  3278.  70 open 2,dn,2,"#"
  3279.  80 print:print#2,a$;
  3280.  85 t=1:s=0
  3281.  90 print#15,"b-a:"d$;t;s
  3282.  100 input#15,en,em$,et,es
  3283.  110 if en=0 then 130
  3284.  115 if et=0 then 200:rem end
  3285.  120 print#15,"b-a:"d$;et;es:t=et:s=es
  3286.  130 print#15,"u2:2,"d$;t;s
  3287.  134 nb=nb+1:print" checked  blocks"nb
  3288.  135 print " track    {left*4}" t;" sector    {left*4}" s "{up*2}"
  3289.  140 input#15,en,em$,et,es
  3290.  150 if en=0 then 85
  3291.  160 t(j)=t:s(j)=s:j=j+1
  3292.  165 print "{down*2}bad block:{left*2}",t;s""
  3293.  170 goto 85
  3294.  200 print#15,"i" d$
  3295.  210 gosub 900
  3296.  212 close 2
  3297.  215 if j=0 then print "{down*3}{right*3}no bad blocks!":end
  3298.  217 open 2,dn,2,"#"
  3299.  218 print "{down*2}bad blocks","track","sector"
  3300.  220 for i=0 to j-1
  3301.  230 print#15,"b-a:";d$,t(i);s(i)
  3302.  240 print,,t(i),s(i)
  3303.  250 next
  3304.  260 print "{down}" j "bad blocks have been allocated"
  3305.  270 close 2:end
  3306.  900 input#15,en,em$,et,es
  3307.  910 if en=0 then return
  3308.  920 print "{down*2}error #"en,em$;et;es""
  3309.  930 print#15,"i" d$
  3310. stop tok64
  3311.  
  3312. begin 644 CHEKDISK.PRG
  3313. M`0@="`$`CR!#2$5#2R!$25-+("TM(%9%4B`Q+C0`/0@"`$1.LC@ZCR!&3$]0
  3314. M4%D@1$5624-%($Y534)%4@!M"`4`AB!4*#$P,"DZAB!3*#$P,"DZCR!"040@
  3315. M5%)!0TLL(%-%0U1/4B!!4E)!60"/"`D`F2`BDQ$1$:^OKZ^OKZ^OKZ^OKZ^O
  3316. MKZ^OKZ^OKR(`JP@*`)D@(B!#2$5#2R!$25-+(%!23T=204TB`,D(#`"9("*W
  3317. MM[>WM[>WM[>WM[>WM[>WM[>WM[<B`-0(%`!$)+(B,"(`XP@>`)\@,34L1$XL
  3318. M,34`\0@C`)@Q-2PB5B)$)``""2T`3B6RNRA422FL,C4U`#`),@!!)+(B(CJ!
  3319. M($FR,2"D(#(U-3I!)+)!)*K'*#(U-2"O("A)JDXE*2DZ@@`Z"3P`C2`Y,#``
  3320. M2PE&`)\@,BQ$3BPR+"(C(@!8"5``F3J8,BQ!)#L`9`E5`%2R,3I3LC``>0E:
  3321. M`)@Q-2PB0BU!.B)$)#M4.U,`C@ED`(0Q-2Q%3BQ%320L150L15,`GPEN`(L@
  3322. M14ZR,""G(#$S,`"V"7,`BR!%5+(P(*<@,C`P.H\@14Y$`-<)>`"8,34L(D(M
  3323. M03HB1"0[150[15,Z5+)%5#I3LD53`.T)@@"8,34L(E4R.C(L(D0D.U0[4P`/
  3324. M"H8`3D*R3D*J,3J9(B!#2$5#2T5$("!"3$]#2U,B3D(`00J'`)D@(B!44D%#
  3325. M2R`@(""=G9V=(B!4.R(@4T5#5$]2("`@()V=G9TB(%,@(I&1(@!6"HP`A#$U
  3326. M+$5.+$5-)"Q%5"Q%4P!F"I8`BR!%3K(P(*<@.#4`?@J@`%0H2BFR5#I3*$HI
  3327. MLE,Z2K)*JC$`FPJE`)D@(A$10D%$($),3T-+.IV=(BQ4.U,B(@"D"JH`B2`X
  3328. M-0"S"L@`F#$U+"))(B!$)`"]"M(`C2`Y,#``Q0K4`*`@,@#L"M<`BR!*LC`@
  3329. MIR"9("(1$1$='1U.3R!"040@0DQ/0TM3(2(Z@`#]"MD`GR`R+$1.+#(L(B,B
  3330. M`",+V@"9("(1$4)!1"!"3$]#2U,B+")44D%#2R(L(E-%0U1/4B(`,PO<`($@
  3331. M2;(P(*0@2JLQ`$\+Y@"8,34L(D(M03HB.T0D+%0H22D[4RA)*0!@"_``F2PL
  3332. M5"A)*2Q3*$DI`&8+^@""`),+!`&9("(1(B!*(")"040@0DQ/0TM3($A!5D4@
  3333. M0D5%3B!!3$Q/0T%4140B`)T+#@&@(#(Z@`"R"X0#A#$U+$5.+$5-)"Q%5"Q%
  3334. M4P#!"XX#BR!%3K(P(*<@C@#A"Y@#F2`B$1%%4E)/4B`C(D5.+$5-)#M%5#M%
  3335. 54R(B`/`+H@.8,34L(DDB($0D````
  3336. `
  3337. end
  3338.  
  3339.  
  3340. 5. PERFORMANCE TEST
  3341.  
  3342. start tok64 perftest.prg
  3343.  1000 rem  performance test  2.0
  3344.  1010 :
  3345.  1020 rem  vic-20 and commodore 64
  3346.  1030 rem  single floppy drive
  3347.  1040 :
  3348.  1050 open 1,8,15:open 15,8,15
  3349.  1060 lt=35
  3350.  1070 lt$=str$(lt)
  3351.  1080 nt=30
  3352.  1090 print "{clear}{down}{175*22}"
  3353.  1100 print "   performance test"
  3354.  1110 print "{183*22}"
  3355.  1120 print
  3356.  1130 print "  insert scratch"
  3357.  1140 print
  3358.  1150 print "    diskette in drive"
  3359.  1160 print
  3360.  1170 print "{down}   press {reverse on}return{reverse off}"
  3361.  1180 print
  3362.  1190 print "          when ready{down}"
  3363.  1200 for i=0 to 50:get a$:next
  3364.  1210 get a$:if a$<>chr$(13) then 1210
  3365.  1220 :
  3366.  1230 :
  3367.  1240 ti$="000000"
  3368.  1250 tt=18
  3369.  1260 print#1,"n0:test disk,00"
  3370.  1270 c1$="   disk new command   "+chr$(13)
  3371.  1280 c2$="{down} wait about 80 seconds"
  3372.  1290 cc$=c1$+c2$:gosub 1840
  3373.  1300 if ti<nt then 1370
  3374.  1310 print "{down}system is"
  3375.  1320 print "{down}        not responding"
  3376.  1330 print "correctly to commands"
  3377.  1340 gosub 1880
  3378.  1350 :
  3379.  1360 :
  3380.  1370 print "{down}drive pass"
  3381.  1380 print "       mechanical test{down}"
  3382.  1390 tt=21
  3383.  1400 open 2,8,2,"0:test file,s,w"
  3384.  1410 cc$="open write file":gosub 1840
  3385.  1420 ch=2:cc$="write data":gosub 1930
  3386.  1430 cc$="close "+cc$:gosub 1840
  3387.  1440 open 2,8,2,"0:test file,s,r"
  3388.  1450 cc$="open read file":gosub 1840
  3389.  1460 ch=2:gosub 1990
  3390.  1470 print#1,"s0:test file"
  3391.  1480 cc$="scratch file{down}":tt=1:gosub 1840
  3392.  1490 :
  3393.  1500 :
  3394.  1510 tt=21
  3395.  1520 open 4,8,4,"#"
  3396.  1530 nn%=(1+rnd(ti)*254+nn%)and 255:print#1,"b-p";4;nn%
  3397.  1540 nn$="":for i=1 to 255:nn$=nn$+chr$(i):next
  3398.  1550 print#4,nn$
  3399.  1560 print#1,"u2:";4;0;lt;0
  3400.  1570 cc$="write track"+lt$:gosub 1840
  3401.  1580 print#1,"u2:";4;0;1;0
  3402.  1590 cc$="write track 1":gosub 1840
  3403.  1600 print#1,"u1:";4;0;lt;0
  3404.  1610 cc$="read track"+lt$:gosub 1840
  3405.  1620 print#1,"u1:";4;0;1;0
  3406.  1630 cc$="read track 1":gosub 1840
  3407.  1640 close 4
  3408.  1650 :
  3409.  1660 :
  3410.  1670 print "{down} unit has passed"
  3411.  1680 print "     performance test!"
  3412.  1690 print "{down} pull diskette from"
  3413.  1700 print "{down}  drive before turning"
  3414.  1710 print "   power off."
  3415.  1720 end
  3416.  1730 :
  3417.  1740 :
  3418.  1750 print "   {down}continue (y/n)?";
  3419.  1760 for i=0 to 50:get a$:next
  3420.  1770 get a$:if a$="" then 1770
  3421.  1780 print a$ "{down}"
  3422.  1790 if a$="n" then end
  3423.  1800 if a$="y" then return
  3424.  1810 goto 1760
  3425.  1820 :
  3426.  1830 :
  3427.  1840 print cc$
  3428.  1850 input#1,en,em$,et,es
  3429.  1860 print tab(12)""en;em$;et;es;""
  3430.  1870 if en<2 then return
  3431.  1880 print "{down} unit is failing"
  3432.  1890 print "{down}   performance test"
  3433.  1900 tm$=ti$:gosub 1750:ti$=tm$:return
  3434.  1910 :
  3435.  1920 :
  3436.  1930 print "writing data"
  3437.  1940 for i=1000 to 2000:print# ch,i:next
  3438.  1950 gosub 1850
  3439.  1960 close ch:return
  3440.  1970 :
  3441.  1980 :
  3442.  1990 print "reading data"
  3443.  2000 get a$
  3444.  2010 for i=1000 to 2000
  3445.  2020 input# ch,j
  3446.  2030 if j<>i then print "{reverse on}read error:{reverse off}":\
  3447.       gosub 1850
  3448.  2040 next
  3449.  2050 gosub 1850
  3450.  2060 close ch:return
  3451. stop tok64
  3452.  
  3453. begin 644 PERFTEST.PRG
  3454. M`0@>".@#CR`@4$521D]234%.0T4@5$535"`@,BXP`"0(\@,Z`$,(_`./("!6
  3455. M24,M,C`@04Y$($-/34U/1$]212`V-`!>"`8$CR`@4TE.1TQ%($9,3U!062!$
  3456. M4DE610!D"!`$.@!["!H$GR`Q+#@L,34ZGR`Q-2PX+#$U`(4()`1,5+(S-0"3
  3457. M""X$3%0DLL0H3%0I`)T(.`1.5+(S,`"^"$($F2`BDQ&OKZ^OKZ^OKZ^OKZ^O
  3458. MKZ^OKZ^OKZ^O(@#:"$P$F2`B("`@4$521D]234%.0T4@5$535"(`^0A6!)D@
  3459. M(K>WM[>WM[>WM[>WM[>WM[>WM[>WM[<B`/\(8`29`!@):@29("(@($E.4T52
  3460. M5"!30U)!5$-((@`>"70$F0`\"7X$F2`B("`@($1)4TM%5%1%($E.($12259%
  3461. M(@!""8@$F0!="9($F2`B$2`@(%!215-3(!)215154DZ2(@!C"9P$F0"!":8$
  3462. MF2`B("`@("`@("`@(%=(14X@4D5!1%D1(@"7";`$@2!)LC`@I"`U,#JA($$D
  3463. M.H(`LPFZ!*$@020ZBR!!)+.QQR@Q,RD@IR`Q,C$P`+D)Q`0Z`+\)S@0Z`-`)
  3464. MV`14222R(C`P,#`P,"(`V@GB!%14LC$X`/,)[`28,2PB3C`Z5$535"!$25-+
  3465. M+#`P(@`:"O8$0S$DLB(@("!$25-+($Y%5R!#3TU-04Y$("`@(JK'*#$S*0`\
  3466. M"@`%0S(DLB(1(%=!250@04)/550@.#`@4T5#3TY$4R(`4PH*!4-#)+)#,22J
  3467. M0S(D.HT@,3@T,`!F"A0%BR!42;-.5""G(#$S-S``>0H>!9D@(A%365-414T@
  3468. M25,B`)D**`69("(1("`@("`@("!.3U0@4D534$].1$E.1R(`MPHR!9D@(D-/
  3469. M4E)%0U1,62!43R!#3TU-04Y$4R(`P@H\!8T@,3@X,`#("D8%.@#."E`%.@#B
  3470. M"EH%F2`B$412259%(%!!4U,B``(+9`69("(@("`@("`@345#2$%.24-!3"!4
  3471. M15-4$2(`#`MN!514LC(Q`"H+>`6?(#(L."PR+"(P.E1%4U0@1DE,12Q3+%<B
  3472. M`$L+@@5#0R2R(D]014X@5U))5$4@1DE,12(ZC2`Q.#0P`&P+C`5#2+(R.D-#
  3473. M)+(B5U))5$4@1$%402(ZC2`Q.3,P`(@+E@5#0R2R(D-,3U-%("*J0T,D.HT@
  3474. M,3@T,`"F"Z`%GR`R+#@L,BPB,#I415-4($9)3$4L4RQ2(@#&"ZH%0T,DLB)/
  3475. M4$5.(%)%040@1DE,12(ZC2`Q.#0P`-8+M`5#2+(R.HT@,3DY,`#L"[X%F#$L
  3476. M(E,P.E1%4U0@1DE,12(`$`S(!4-#)+(B4T-2051#2"!&24Q%$2(Z5%2R,3J-
  3477. M(#$X-#``%@S2!3H`'`S<!3H`)@SF!514LC(Q`#8,\`6?(#0L."PT+"(C(@!D
  3478. M#/H%3DXELB@QJKLH5$DIK#(U-*I.3B4IKR`R-34ZF#$L(D(M4"([-#M.3B4`
  3479. MB@P$!DY.)+(B(CJ!($FR,2"D(#(U-3I.3B2R3DXDJL<H22DZ@@"5#`X&F#0L
  3480. M3DXD`*L,&`:8,2PB53(Z(CLT.S`[3%0[,`#,#"(&0T,DLB)74DE412!44D%#
  3481. M2R*J3%0D.HT@,3@T,`#A#"P&F#$L(E4R.B([-#LP.S$[,```#38&0T,DLB)7
  3482. M4DE412!44D%#2R`Q(CJ-(#$X-#``%@U`!I@Q+")5,3HB.S0[,#M,5#LP`#8-
  3483. M2@9#0R2R(E)%040@5%)!0TLBJDQ4)#J-(#$X-#``2PU4!I@Q+")5,3HB.S0[
  3484. M,#LQ.S``:0U>!D-#)+(B4D5!1"!44D%#2R`Q(CJ-(#$X-#``<0UH!J`@-`!W
  3485. M#7(&.@!]#7P&.@"7#88&F2`B$2!53DE4($A!4R!005-3140B`+8-D`:9("(@
  3486. M("`@(%!%4D9/4DU!3D-%(%1%4U0A(@#3#9H&F2`B$2!054Q,($1)4TM%5%1%
  3487. M($923TTB`/,-I`:9("(1("!$4DE612!"149/4D4@5%523DE.1R(`"0ZN!ID@
  3488. M(B`@(%!/5T52($]&1BXB``\.N`:``!4.P@8Z`!L.S`8Z`#@.U@:9("(@("`1
  3489. M0T].5$E.544@*%DO3BD_(CL`3@[@!H$@2;(P(*0@-3`ZH2!!)#J"`&8.Z@:A
  3490. M($$D.HL@022R(B(@IR`Q-S<P`',.]`:9($$D("(1(@"$#OX&BR!!)+(B3B(@
  3491. MIR"``)4."`>+($$DLB)9(B"G((X`H`X2!XD@,3<V,`"F#AP'.@"L#B8'.@"V
  3492. M#C`'F2!#0R0`R@XZ!X0Q+$5.+$5-)"Q%5"Q%4P#F#D0'F2"C,3(I(B)%3CM%
  3493. M320[150[15,[(B(`]0Y.!XL@14ZS,B"G((X`#P]8!YD@(A$@54Y)5"!)4R!&
  3494. M04E,24Y'(@`L#V('F2`B$2`@(%!%4D9/4DU!3D-%(%1%4U0B`$D/;`=4322R
  3495. M5$DD.HT@,3<U,#I4222R5$TD.HX`3P]V!SH`50^`!SH`:@^*!YD@(E=2251)
  3496. M3D<@1$%402(`AP^4!X$@2;(Q,#`P(*0@,C`P,#J8($-(+$DZ@@"2#YX'C2`Q
  3497. M.#4P`)T/J`>@($-(.HX`HP^R!SH`J0^\!SH`O@_&!YD@(E)%041)3D<@1$%4
  3498. M02(`QP_0!Z$@020`VP_:!X$@2;(Q,#`P(*0@,C`P,`#F#^0'A"!#2"Q*``P0
  3499. M[@>+($JSL4D@IR"9("(24D5!1"!%4E)/4CJ2(CJ-(#$X-3``$A#X!X(`'1`"
  3500. 5"(T@,3@U,``H$`P(H"!#2#J.````
  3501. `
  3502. end
  3503.  
  3504.  
  3505.  
  3506. APPENDIX D: DISK FORMATS
  3507.  
  3508.            [ Outer Rim ]
  3509.  ------------------------------------
  3510.               Track 1
  3511.   ----------------------------------
  3512.  
  3513.    --------------------------------
  3514.          Track 18 (Directory)
  3515.     ------------------------------
  3516.  
  3517.      ----------------------------
  3518.               Track 35    O Index Hole
  3519.       --------------------------
  3520.            [ Center Hub ]
  3521.  
  3522.  
  3523.     1540/1541 Format: Expanded View of a Single Sector
  3524.  
  3525.  +------+----+------+------+----+----+-------+-------+------+-
  3526.  | SYNC | 08 | ID 1 | ID 2 | TK | BL | CHECK | GAP 1 | SYNC |
  3527.  |      |    |      |      |    |    |  SUM  |       |      | <-+
  3528.  +------+----+------+------+----+----+-------+-------+------+-  |
  3529.                                                                 |
  3530.  +----------------------- (CONTINUED) --------------------------+
  3531.  |
  3532.  |  -+----+------+------+-----------+-------+-----+
  3533.  |   | 07 | BYTE | BYTE | 254 BYTES | CHECK | GAP |
  3534.  +-> |    |  0   |  1   |  OF DATA  |  SUM  |     |
  3535.     -+----+------+------+-----------+-------+-----+
  3536.  
  3537.  
  3538.          BLOCK DISTRIBUTION BY TRACK
  3539.  +--------------+-------------+-------------+
  3540.  | TRACK NUMBER | BLOCK RANGE | TOTAL BLOCK |
  3541.  +--------------+-------------+-------------+
  3542.  |    1 to 17   |   0 to 20   |      21     |
  3543.  |   18 to 24   |   0 to 18   |      19     |
  3544.  |   25 to 30   |   0 to 17   |      18     |
  3545.  |   31 to 35   |   0 to 16   |      17     |
  3546.  +--------------+-------------+-------------+
  3547.  
  3548.  
  3549.                         1540/1541 BAM FORMAT
  3550.  +-----------------------------------------------------------------+
  3551.  | Track 18, Sector 0.                                             |
  3552.  +-------+----------+----------------------------------------------+
  3553.  | BYTE  | CONTENTS |                DEFINITION                    |
  3554.  +-------+----------+----------------------------------------------+
  3555.  | 0,1   | 18,01    | Track and sector of first directory block.   |
  3556.  +-------+----------+----------------------------------------------+
  3557.  | 2     | 65       | ASCII character A indicating 4040 format.    |
  3558.  +-------+----------+----------------------------------------------+
  3559.  | 3     | 0        | Null flag for future DOS use.                |
  3560.  +-------+----------+----------------------------------------------+
  3561.  | 4-143 |          | Bit map of available blocks for tracks 1-35. |
  3562.  +-------+----------+----------------------------------------------+
  3563.  | *1 = available block                                            |
  3564.  |  0 = block not available                                        |
  3565.  |      (each bit represents one block)                            |
  3566.  +-----------------------------------------------------------------+
  3567.  
  3568.  
  3569.                       1540/1541 DIRECTORY HEADER
  3570.  +-----------------------------------------------------------------+
  3571.  | Track 18, Sector 0.                                             |
  3572.  +---------+----------+--------------------------------------------+
  3573.  | BYTE    | CONTENTS |              DEFINITION                    |
  3574.  +---------+----------+--------------------------------------------+
  3575.  | 144-161 |          | Disk name padded with shifted spaces.      |
  3576.  +---------+----------+--------------------------------------------+
  3577.  | 162-163 |          | Disk ID.                                   |
  3578.  +---------+----------+--------------------------------------------+
  3579.  | 164     | 160      | Shifted space.                             |
  3580.  +---------+----------+--------------------------------------------+
  3581.  | 165,166 | 50,65    | ASCII representation for 2A which is DOS   |
  3582.  |         |          | version and format type.                   |
  3583.  +---------+----------+--------------------------------------------+
  3584.  | 166-167 | 160      | Shifted spaces.                            |
  3585.  +---------+----------+--------------------------------------------+
  3586.  | 171-255 | 0        | Nulls, not used.                           |
  3587.  +---------+----------+--------------------------------------------+
  3588.  | Note: ASCII characters may appear in locations 180 thru 191 on  |
  3589.  |       some diskettes.                                           |
  3590.  +-----------------------------------------------------------------+
  3591.  
  3592.  
  3593.                         SEQUENTIAL FORMAT
  3594.  +---------+-------------------------------------------------------+
  3595.  | BYTE    |              DEFINITION                               |
  3596.  +---------+-------------------------------------------------------+
  3597.  | 0,1     | Track and sector of next sequential data block.       |
  3598.  +---------+-------------------------------------------------------+
  3599.  | 2-256   | 254 bytes of data with carriage returns as record     |
  3600.  |         | terminators.                                          |
  3601.  +---------+-------------------------------------------------------+
  3602.  
  3603.  
  3604.                        PROGRAM FILE FORMAT
  3605.  +---------+-------------------------------------------------------+
  3606.  | BYTE    |              DEFINITION                               |
  3607.  +---------+-------------------------------------------------------+
  3608.  | 0,1     | Track and sector of next block in program file.       |
  3609.  +---------+-------------------------------------------------------+
  3610.  | 2-256   | 254 bytes of program info stored in CBM memory format |
  3611.  |         | (with key words tokenized).  End of file is marked by |
  3612.  |         | three zero bytes.                                     |
  3613.  +---------+-------------------------------------------------------+
  3614.  
  3615.  
  3616.                        DIRECTORY FORMAT
  3617.  +---------------------------------------------------------+
  3618.  | Track 18, Sector 1 for 1540/1541                        |
  3619.  +---------+-----------------------------------------------+
  3620.  | BYTE    |               DEFINITION                      |
  3621.  +---------+-----------------------------------------------+
  3622.  | 0,1     | Track and sector of next directory block.     |
  3623.  +---------+-----------------------------------------------+
  3624.  | 2-31    | *File entry 1                                 |
  3625.  +---------+-----------------------------------------------+
  3626.  | 34-63   | *File entry 2                                 |
  3627.  +---------+-----------------------------------------------+
  3628.  | 66-95   | *File entry 3                                 |
  3629.  +---------+-----------------------------------------------+
  3630.  | 98-127  | *File entry 4                                 |
  3631.  +---------+-----------------------------------------------+
  3632.  | 130-159 | *File entry 5                                 |
  3633.  +---------+-----------------------------------------------+
  3634.  | 162-191 | *File entry 6                                 |
  3635.  +---------+-----------------------------------------------+
  3636.  | 194-223 | *File entry 7                                 |
  3637.  +---------+-----------------------------------------------+
  3638.  | 226-255 | *File entry 8                                 |
  3639.  +---------+-----------------------------------------------+
  3640.  
  3641. *STRUCTURE OF SINGLE DIRECTORY ENTRY
  3642.  
  3643.  +---------+----------+--------------------------------------------+
  3644.  | BYTE    | CONTENTS |              DEFINITION                    |
  3645.  +---------+----------+--------------------------------------------+
  3646.  | 0       | 128+type | File type OR'ed with $80 (hexadecimal) to  |
  3647.  |         |          | indicate properly closed file.             |
  3648.  |         |          | TYPES: 0 = DELeted                         |
  3649.  |         |          |        1 = SEQential                       |
  3650.  |         |          |        2 = PROGram                         |
  3651.  |         |          |        3 = USER                            |
  3652.  |         |          |        4 = RELative                        |
  3653.  +---------+----------+--------------------------------------------+
  3654.  | 1,2     |          | Track and sector of 1st data block.        |
  3655.  +---------+----------+--------------------------------------------+
  3656.  |         |          | File name padded with shifted spaces.      |
  3657.  +---------+----------+--------------------------------------------+
  3658.  |         |          | Relative file only: track and sector for   |
  3659.  |         |          | first side sector block.                   |
  3660.  +---------+----------+--------------------------------------------+
  3661.  |         |          | Relative file only: Record size.           |
  3662.  +---------+----------+--------------------------------------------+
  3663.  |         |          | Unused.                                    |
  3664.  +---------+----------+--------------------------------------------+
  3665.  |         |          | Track and sector of replacement file when  |
  3666.  |         |          | OPEN@ is in effect.                        |
  3667.  +---------+----------+--------------------------------------------+
  3668.  |         |          | Number of blocks in file: low byte, high   |
  3669.  |         |          | byte.                                      |
  3670.  +---------+----------+--------------------------------------------+
  3671.  
  3672.  
  3673.                     RELATIVE FILE FORMAT
  3674.  +---------------------------------------------------------------+
  3675.  | DATA BLOCK                                                    |
  3676.  +---------------------------------------------------------------+
  3677.  | BYTE   | DEFINITION                                           |
  3678.  +--------+------------------------------------------------------+
  3679.  | 0,1    | Track and block of next data block.                  |
  3680.  +--------+------------------------------------------------------+
  3681.  | 2-256  | 254 bytes of data. Empty records contain FF (all     |
  3682.  |        | binary ones) in the first byte followed by 00        |
  3683.  |        | (binary all zeros) to the end of the record.         |
  3684.  |        | Partially filled records are padded with nulls (00). |
  3685.  +---------------------------------------------------------------+
  3686.  | SIDE SECTOR BLOCK                                             |
  3687.  +--------+------------------------------------------------------+
  3688.  | BYTE   | DEFINITION                                           |
  3689.  +--------+------------------------------------------------------+
  3690.  | 0,1    | Track and block of next side sector block.           |
  3691.  +--------+------------------------------------------------------+
  3692.  | 2      | Side sector number. (0-5)                            |
  3693.  +--------+------------------------------------------------------+
  3694.  | 3      | Record length.                                       |
  3695.  +--------+------------------------------------------------------+
  3696.  | 4,5    | Track and block of first side sector (number 0)      |
  3697.  +--------+------------------------------------------------------+
  3698.  | 6,7    | Track and block of second side sector (number 1)     |
  3699.  +--------+------------------------------------------------------+
  3700.  | 8,9    | Track and block of third side sector (number 2)      |
  3701.  +--------+------------------------------------------------------+
  3702.  | 10,11  | Track and block of fourth side sector (number 3)     |
  3703.  +--------+------------------------------------------------------+
  3704.  | 12,13  | Track and block of fifth side sector (number 4)      |
  3705.  +--------+------------------------------------------------------+
  3706.  | 14,15  | Track and block of sixth side sector (number 5)      |
  3707.  +--------+------------------------------------------------------+
  3708.  | 16-256 | Track and block pointers to 120 data blocks.         |
  3709.  +--------+------------------------------------------------------+
  3710.  
  3711.  
  3712.  
  3713. INDEX [ by Section Number ]
  3714.  
  3715. A
  3716.  Assembly Language, 10
  3717.  
  3718. B
  3719.  BLOCK-ALLOCATE, 6.5, A
  3720.  Block Availability Map (BAM), 3.3, 5.4, 6.1, 6.5, D
  3721.  BLOCK-EXECUTE, 8.1, A
  3722.  BLOCK-FREE, 6.6, A
  3723.  BLOCK-READ, 6.1, 6.3, 6.7, 6.8, 6.9, A
  3724.  Blocks, 1.2, 6.9, D
  3725.  BLOCK-WRITE, 6.4, 6.7, 6.9, A
  3726.  Buffer, 1.2, 6.8
  3727.  BUFFER-POINTER, 6.8, A
  3728.  
  3729. C
  3730.  CLOSE, 4.10
  3731.  COPY, 4.3, A
  3732.  
  3733. D
  3734.  Data Channel, 6.2
  3735.  Demonstration Disk Programs, C
  3736.  Device Number, 5.1, 9.1-9.2
  3737.  Directory, 3.3, 5.4, D
  3738.  Disk Controller, 8.1-8.5
  3739.  Disk Operating System (DOS), 3.3-3.4, 3.8, 5.4, 6.1, 6.5, 6.8, B
  3740.  DOS Support Program, 3.8, 4.9
  3741.  Drive Speeds, 2.5
  3742.  DUPLICATE, 4.8, A
  3743.  
  3744. E
  3745.  End-of-file (EOF), 5.2
  3746.  Error Channel, 4.9, 7.5, 8.2
  3747.  Error Messages, B
  3748.  
  3749. F
  3750.  FORMAT (see NEW)
  3751.  
  3752. G
  3753.  GET#, 5.3
  3754.  
  3755. I
  3756.  INITIALIZE, 4.6, 8.3, A
  3757.  INPUT#, 4.9, 5.2, 7.4
  3758.  
  3759. L
  3760.  LOAD, 1.1 3.2-3.5, 3.7-3.8, 4.1, 4.10
  3761.  
  3762. M
  3763.  Mailing List Program, 7.3
  3764.  MEMORY-EXECUTE, 8.4, A
  3765.  MEMORY-READ, 8.2, A
  3766.  MEMORY-WRITE, 8.3, A
  3767.  
  3768. N
  3769.  NEW, 4.2, A
  3770.  
  3771. O
  3772.  Open, 4.1, 5.1
  3773.  
  3774. P
  3775.  Pattem Matching, 3.4
  3776.  POSITION, 7.3-7.4, A
  3777.  PRINT#, 4.1, 5.2
  3778.  Program Files (PRG), 5.1, 5.4, C
  3779.  
  3780. R
  3781.  Random Files, 1.2, 6.1-6.8
  3782.  Relative Files (REL), 1.1-1.2, 5.1, 6.8-6.9, 7.1-7.6, D
  3783.  RENAME, 4.4, A
  3784.  
  3785. S
  3786.  SAVE, 1.1, 3.5-3.6, 4.7
  3787.  SCRATCH, 4.5, 4.7, A
  3788.  Sectors, 1.2, D
  3789.  Sequential Files (SEQ), 1.1-1.2, 5.1-5.3, 5.4, 6.7, D
  3790.  Serial Bus Interface, 1.2, 2.3, 2.5
  3791.  Side Sector, 7.1-7.2
  3792.  Specifications, 1.2
  3793.  
  3794. T
  3795.  Tracks, 6.1, 6.8, D
  3796.  
  3797. U
  3798.  USER, 8.5, A
  3799.  User Files (USR), 5.1, 5.4, 6.9
  3800.  
  3801. V
  3802.  VALIDATE, 4.7, A
  3803.  VERIFY, 3.7, A
  3804.  
  3805. W
  3806.  Wedge, 3.8, 8
  3807.  Wild Cards, 3.4
  3808.  
  3809.  
  3810.  
  3811. COMMODORE SALES CENTERS
  3812.  
  3813.  Commodore Business Machines, Inc.
  3814.  1200 Wilson Drive
  3815.  Westchester, PA 19380, U.S.A.
  3816.  
  3817.  Commodore Business Machines Ltd.
  3818.  3370 Pharmacy Avenue, Agincourt,
  3819.  Ontario, M1W 2K4, Canada
  3820.  
  3821.  Commodore Business Machines (UK) Ltd.
  3822.  675 Ajax Avenue, Trading Estate,
  3823.  Slough Berks, SL1 4BG, England
  3824.  
  3825.  Commodore Bueromashinen GmbH
  3826.  Lyonerstrasse 38, PO BOX 710126
  3827.  Frankfult 6000, West Germany
  3828.  
  3829.  Commodore Italians S.R.L.
  3830.  Via Conservatoria 22
  3831.  Milano 20122, Italy
  3832.  
  3833.  Commodore Information Center
  3834.  5 Onion Road
  3835.  Lane Cove 2066 NSW, Australia
  3836.  
  3837.  Commodore Computer B.V.
  3838.  Marksingel 2e4811 N.V. Breda
  3839.  Postlrus 720, 480 3aS Breda, Netherlands
  3840.  
  3841.  Commodore AG (Schweiz)
  3842.  Aeschenvorstadt 57
  3843.  4010 Basel, Switzerland
  3844.  
  3845.  
  3846.  
  3847. [ BACK PAGE ]
  3848.  
  3849. DISK DRIVES
  3850.  
  3851. MODEL SFD 1001 -- 1 Megabyte double sided, floppy disk drive. Uses
  3852. double density, double sided diskettes. IEEE interface.
  3853.  
  3854. MODEL 2031LP -- Media compatible with 1541 and 4040 diskettes. 170 K
  3855. of memory per single side disk.  Rugged and stylish housing. IEEE
  3856. interface.
  3857.  
  3858.  
  3859. PRINTERS
  3860.  
  3861. MODEL MPS-801 -- High quality dot matrix printing.  80 column printing.
  3862. Prints 50 characters per second.  Serial port interface.
  3863.  
  3864. MODEL MSC-801 -- Seven color, dot matrix printing.  Up to 80 columns
  3865. printed per page.  Prints 38 characters per second.  Perfect for
  3866. everything from personal letters to important business reports. Serial
  3867. port interface.
  3868.  
  3869. MODEL 1526 -- 80 column, dot mtrix printing. Prints 80 characters per
  3870. second.  Durability at an affordable price. Serial Port interface.
  3871.  
  3872.  
  3873. PRINTER/PLOTTER
  3874.  
  3875. MODEL 1520 -- Four color, printer/plotter for all graphic needs. Print
  3876. bar graphs...create pie charts...plot time graphs.  High quality
  3877. printing in a variety of styles and sizes.  Great for graphic artists.
  3878.  
  3879.  
  3880. MODEMS
  3881.  
  3882. VICMODEM -- Timely financial information, news and reference libraries
  3883. are as near as your phone.  An affordable introduction to the growing
  3884. world of phone/computer services.  Communicate with a wide variety of
  3885. computer users who already own a modem.
  3886.  
  3887. AUTOMODEM -- The convenience of automatic answering and dialing. The
  3888. resource power of telecomputing services.  Turn your phone into a
  3889. telecomputing information network.
  3890.  
  3891.  
  3892.    _____
  3893.   /  ___|___
  3894.  |  /   |__/  c o m m o d o r e
  3895.  |  \___|__\  C O M P U T E R
  3896.   \_____|
  3897.  
  3898. P/N 1540031-02 (5)
  3899.  
  3900. Printed in Japan
  3901.  
  3902. *********
  3903.  
  3904. End of the Project 64 etext of the Commodore 1541 Disk Drive User's
  3905. Guide, first edition.
  3906.  
  3907. *********
  3908.  
  3909.